Specify conftest / setup file in the ini file
See original GitHub issueDescription
Apparently my codebase uses this project so I’m just stumbling upon this, so forgive my ignorance if this exists or handled in another way
I’ve been trying to understand how the whole conftest.py system works cause I have two issues
- Specific file testing doesn’t use
conftest.py
i.e. tests don’t work if you want to run them individually - Can’t specify a conftest depending on the testing style (we use unit + integration for example)
To elaborate on 1:
pytest -s -c=./config/python/pytest_unit.ini path/to/tests/file_test.py
if I put a conftest anywhere (path/*
, or path/to/tests/*
) it is not detected, but running without a path does detect it
To elaborate on 2:
I might want to disable internet access or setup mocks depending on the type of test I want to run (we use different ini files and suffix based file detection) but I don’t see the option in: https://docs.pytest.org/en/latest/reference.html#ini-options-ref (there is a useFixture but that doesn’t seem to solve my problem)
example unit.ini:
[pytest]
testpaths=path
python_files = *_test.py
addopts = --tb=native --disable-pytest-warnings
# Add this:
setup_file=path/setup_pytest.py
Extra
I’m getting ahead of myself but if this is something to add then pls comment with the places of which files to change (i.e. where the definitions are and where the code should go) if someone wants to write a PR so that they’re not daunted by the new codebase
Issue Analytics
- State:
- Created 4 years ago
- Comments:24 (12 by maintainers)
@Azee77 the code changes needed should be fairly minimal, rename a file to something other than
conftest.py
so it is not included according to the conftest discovery rules, and then make that new name visible by including it in the root conftest.py file via thepytest_plugins = [...]
mechanism. You still need to be sure your rootdir is set properly for that plugin to be visible from where you’re invoking, which hopefully was the repo1 level.You might get some insight working through this set of pytest examples I wrote up recently https://github.com/jxramos/pytest_behavior
Thanks for the issue grooming btw Zac, appreciate it! Closing old issues without resolution sometimes is the ping needed to bring an issue back to attention. 😁