Closed mgorny closed 1 year ago
Tavern is registered using Pytest entry points https://docs.pytest.org/en/7.1.x/how-to/writing_plugins.html and will always be picked up if it's installed globally on your system. If you don't want it to always be picked up, you need to install it in a virtualenv instead (see https://docs.python.org/3/library/venv.html https://pypi.org/project/virtualenv/)
This won't work for Linux distribution packaging where all packages have to be installed globally.
On looking further, this is happening because Tavern needs to overwrite some global state in pyyaml (because it doesn't expose another way to do this easily). I might be able to make it so that it only does this when it loads a Tavern test, but it would still fail in a 'mixed environment' where you're running multiple different kinds of tests.
The easiest answer to the original problem is still just to create a virtualenv to run Tavern tests, and not rely on having any Python packages installed globally.
I actually think the cleanest and most correct solution would be to have the intrusive patching off by default and enabled via pytest.ini
.
Oh, and I should probably clarify that we are using virtualenv but with --system-site-packages
, to ensure that the package in question is tested in the exact same context as it will be used once installed.
in 1.25.2, pyyaml will only be patched if a Tavern test is actually being loaded which should stop unwanted side effects.
If tavern is installed on the system (tested with 1.24.1) test suites of other packages are implicitly broken. This is a very bad practice since tavern can be installed as a dependency of one package but at the same time break other packages in unpredictable ways.
For example, the test suite of apispec fails two tests:
However, apispec never meant to use tavern, doesn't specify anything that would request using tavern and I honestly doubt upstream would consider it a valid bug if I reported these test failures.