0
votes

Im building a test runner package, with custom fixtures, pytest.ini and conftest. I want this runner to be able to accept as parameter a directory path, and collect the tests in that path and run them using my custom configuration files.

What Im doing now is copying the given directory to a known location (tests) inside my package and then run pytest programmatically with path to the tests and --rootdir params.

Dir tree:
- runner
---- tests
---- conftest.py
---- pytest.ini
---- fixtures.py
---- runner.py

Python code:
pytest_params = ['tests', '--rootdir=runner', <other params passed to pytest>]
pytest.main([pytest_params])

Which works great. But I dont want to copy the entire tests dir for every run.

Ive tried to set testpaths arg in pytest.ini and remote the path argument from pytest params, but this causes pytest to lose rootdir and pytest.ini files and of course fail.

Any ideas?

1

1 Answers

1
votes

You need to explicitly specify the location of ini file. You can use -c argument to specify the location of your ini file. To load settings from runner directory, you need to run conftest.py with pytest.

You argument would look like this:

pytest_params = ['conftest.py', '-c=pytest.ini', '--rootdir=<path_of_external_tests', <other params passed to pytest>]
pytest.main(pytest_params)