-1

I have a test script written using pytest and it works fine when I execute it as standalone.

User:~my_workspace/python_project$ pytest path_to_script/my_script.py

Now I have to run this script with different parameters and hence I have created a python file (script_to_invoke_pytest.py) so that I can run the pytest script from this python file.

I tried below approaches within my script_to_invoke_pytest.py

#approach 1
import subprocess
subprocess.Popen(['pytest', r'path_to_script/my_script.py'], shell=True)
#approach 2
import pytest
pytest.main([r'path_to_script/my_script.py'])

Both the approaches didn't work and I get errors related no modules named xyz.

Im using pycharm ide and before running pytest, I execute the docker.

Please let me know how can I invoke my pytest from my python script script_to_invoke_pytest.py

1 Answer 1

1

In your second approach, you're not telling python where to find the tests. Try:

import pytest
pytest.main([r'path_to_script/my_script.py'])
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry , I updated my second approach. I tried it , but I get Import errors such as no module named XYZ and so on. These modules loads and works fine , when I run the pytest as standalone.
Thanks. After I placed the script_to_invoke_pytest.py in the same folder of the pytest script. The solution worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.