Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

py.test main() invocation examples

I have this structure.

 /bin 
   __init__.py
   run_test.py (call pytest.main)
 /tests
   __init__.py
   test_xyz.py

If I call run_test.py using simply via pytest.main(), it won't invoke tests in "tests" module. I tried passing couple of parameters like module="tests" etc but they don't work. I have to altogether chuck auto discovery and use the suite parameter for it to pick up any tests.

What am I missing? I tried to walk through the code in the pytest module, but it is way too complex to understand. And the documentation is very bad.

like image 957
Parth Avatar asked Aug 13 '26 09:08

Parth


1 Answers

You can pass the full path of what to execute.

import pytest

pytest_args = [
    '/tests',
    # other tests here...
]
pytest.main(pytest_args)

This will execute all the tests found in the directory, there is no need to have /tests/__init__.py

like image 145
Pedru Avatar answered Aug 15 '26 00:08

Pedru