-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Way to isolate tests from existing environment variables? #4226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
JFI: typically CI systems ensure this by design, and tox can also be used for this (where you have to explicitly use |
IMHO environment isolation is done better by an external tool than adding this to pytest itself, because it is hard to do it correctly from within pytest. |
Agreeing with @nicoddemus, and closing. |
Hmm, seems rather odd to depend on external tools for basic testing functionality, right?
From this I assume it's more complex than just setting |
replacing os.environ is pretty much fundamentally broken and you are lucky if things didn't blow up ^^ |
@RonnyPfannschmidt Do you have any more info on what exactly is fundamentally broken? |
@simonvanderveldt shadowing it with random python data structures just hides away access to the actual data that will still affect subprocesses and c libraries and in addition it breaks expectations for quite a few things out there |
@RonnyPfannschmidt Thanks for the info. So far we're doing pure Python only so I guess we should be fine. Will keep it in mind though for possible future situations :) |
@simonvanderveldt i strongly suggest to limit this hack as intensely as possible - its a really good starting point for unexpected failures |
It could be I've missed something but I've done quiet a bit of searching and it seems there's no out of the box/default way of isolating tests from the environment variables from the calling environment.
Is this something that could be added or was this a conscious design decision?
As a workaround I currently do this in
conftest.py
, which works, though I'm not sure how much I'm abusing the system by doing this :PAnd as an extension of this it would be nice if there would be a way to have this isolation and allow one to globally override/set environment variables before discovery/importing happens, to allow easy testing of modules that make use of environment variables at module level. This sounds similar to #3597
I'd currently do that using:
I guess a more specific hook one could add to
conftests.py
that runs before module discovery/import might be one way to enable something like this.The text was updated successfully, but these errors were encountered: