I would like to create a pip package where one python script can execute the other script over the command line.
Take this as an example:
my-package/
└── my-package
├── script.py
└── tests.py
with script.py:
import pytest
def run():
# run the other script
pytest.main(["tests.py"])
# then do the actual stuff
print("I did something!")
and tests.py:
import pytest
class Test:
def test_stuff(self):
if not 1 == 2:
pytest.fail('1 does not equal 2')
How can I configure my pyproject.toml file so that the run() function inside script.py always "knows" where to find tests.py so it can execute it via pytest.main()? Right now, I have the problem that the run() function expects tests.py to be always in the directory that I am currently in. Of course that's not the case. I need a way to tell the run function that it will find tests.py in the same directory where itself is located.
Note: I saw a few suggestions but they always refer to specific functions inside scripts that are made available as command-line options. But in my case one script should call the whole other script not just one single function inside of it.
Possibly related:
how to run a script using pyproject.toml settings and poetry?