Modular / recursive configuration with multiple pytest.ini in subfolders #7732
|
Hi, i have been searching around about this, but could not find any info. My question is, is it possible somehow to use multiple pytest.ini files in subfolders? What I would like to achieve is that I have a package with several subfolders/subpackages that may contain python files that may contain test functions. These files may not have the |
Replies: 8 comments 2 replies
|
You can use https://docs.pytest.org/en/stable/reference.html#globalvar-collect_ignore_glob in a |
|
How would that help? I need the opposite, I don't want to ignore some files, I would like to additionally collect some. Meanwhile I have played around with |
|
Multiple ini files are not supported and at the moment there are no plans for this, as currently there is no reasonable and time effective way to implement this as a working solution Pytest itself has a hack in the root ini file to support this edit see line 16 of our pyproject.toml (can't make a proper link on mobile) |
|
Thanks. So I guess I would be better off by reorganizing the project and extracting all tests to a separate tests folder. However I still see this as a possible feature, because in our case it is a quite big codebase, and in this case it would be better to have the tests next to the actual modules, or even inside them. |
|
I suppose you could alternatively write a plugin to achieve this (not very familiar with this myself, but seems doable). https://hackebrot.github.io/pytest-tricks/customize_class_collection/ |
|
@waszil How did you solve this? |
|
closing this discussion as config merges are currently not supported and there are no plans to directly include such a feature and there also is no proposal on how to do this safe/sane |
|
For anyone else who got here from google looking for how to merge pytest configs: the Sept 9 2020 reference to "check the pytest pyproject.toml" points at a config that looks like this: [tool.pytest.ini_options]
python_files = ["test_*.py", "*_test.py", "testing/*/*.py"]Which sadly is a hack addressing a different part of OP's question. I haven't found a good way to have multiple pytest config files. |
Multiple ini files are not supported and at the moment there are no plans for this, as currently there is no reasonable and time effective way to implement this as a working solution
Pytest itself has a hack in the root ini file to support this
edit see line 16 of our pyproject.toml (can't make a proper link on mobile)