Open gerritholl opened 3 years ago
I just realized, now that we use pytest we could configure/setup all tests in a conftest.py
in the tests
directory and make it unset these environment variables (it would have to re-set them afterward).
There exists monkeypatch.delenv
for that, which could be set in a global autouse fixture, I think.
Doing it that way would unset/set the env var for every test right?
I was hoping something like this could be put in conftest.py:
https://docs.pytest.org/en/6.2.x/reference.html#pytest.hookspec.pytest_configure
I don't know if I've ever done it though.
Doing it that way would unset/set the env var for every test right?
Depends on the fixture scope, I think. With the default (function) scope, it would run for every test. Isn't that what we want? That way, we also protect against tests which aren't cleaning up after themselves properly. I've seen more than once that a test would pass in isolation, but fail when running the whole suite (and I've even seen the other way around). But I think if the autouse fixture scope was class, module, or session, it would run only once per scope. I might have used that for creating files, but for something as fast as (un)setting an environment variable, I wouldn't expect a noticeable difference.
I'm not familiar with initialisation hooks or plugins in pytest, and I don't understand how it would be different from an autouse fixture with session scope.
True. If you use per-function fixtures in your session-scoped fixtures (monkeypatch in our custom session fixture) it will raise an error.
I'm a little torn on what's best here. Is it better to write code to make it harder for tests to interfere with each other (resetting env every test) or let bad tests mess up other tests environments? I lean towards the latter as we (the maintainers) may not be able to defend against all interference between tests. By hiding side effects of a test we may be also hiding bugs in the actual user-facing code.
Describe the bug
If the environment
SATPY_CONFIG_PATH
is set,test_deprecated_env_vars
intest_config.py
fails.To Reproduce
Expected behaviour
I expect all tests to pass independent of environment variables.
Actual results
Environment Info:
Additional context
This bug falls in the same category as #1763.