-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Make parallel tests insensitive to user configuration #8727
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6328482
Write out custom configuration to the standard location to ensure tha…
astrofrog 2d2b944
Set temporary config/cache in conftest.py since this is needed when r…
astrofrog 6734237
Set temporary directories for config/cache in root-level conftest.py …
astrofrog 861817e
Updated comment
astrofrog c0f7337
Added a conftest.py in docs/ since this is needed if running tests wi…
astrofrog 7ae04f8
Write out user config on Travis that will cause the tests to fail if …
astrofrog 483b912
Added changelog entry
astrofrog 9ab45d3
Don't use pytest_plugins in a non-top-level conftest.py (this is depr…
astrofrog edf94a9
Restore XDG_CONFIG_HOME and XDG_CACHE_HOME after tests where relevant.
astrofrog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
|
||
# This file is the main file used when running tests with pytest directly, | ||
# in particular if running e.g. ``pytest docs/``. | ||
|
||
import os | ||
import tempfile | ||
|
||
pytest_plugins = [ | ||
'astropy.tests.plugins.display', | ||
] | ||
|
||
# Make sure we use temporary directories for the config and cache | ||
# so that the tests are insensitive to local configuration. | ||
|
||
os.environ['XDG_CONFIG_HOME'] = tempfile.mkdtemp('astropy_config') | ||
os.environ['XDG_CACHE_HOME'] = tempfile.mkdtemp('astropy_cache') | ||
|
||
os.mkdir(os.path.join(os.environ['XDG_CONFIG_HOME'], 'astropy')) | ||
os.mkdir(os.path.join(os.environ['XDG_CACHE_HOME'], 'astropy')) | ||
|
||
# Note that we don't need to change the environment variables back or remove | ||
# them after testing, because they are only changed for the duration of the | ||
# Python process, and this configuration only matters if running pytest | ||
# directly, not from e.g. an IPython session. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
|
||
# This file needs to be included here to make sure commands such | ||
# as ``python setup.py test ... -t docs/...`` works, since this | ||
# will ignore the conftest.py file at the root of the repository | ||
# and the one in astropy/conftest.py | ||
|
||
import os | ||
import tempfile | ||
|
||
# Make sure we use temporary directories for the config and cache | ||
# so that the tests are insensitive to local configuration. | ||
|
||
os.environ['XDG_CONFIG_HOME'] = tempfile.mkdtemp('astropy_config') | ||
os.environ['XDG_CACHE_HOME'] = tempfile.mkdtemp('astropy_cache') | ||
|
||
os.mkdir(os.path.join(os.environ['XDG_CONFIG_HOME'], 'astropy')) | ||
os.mkdir(os.path.join(os.environ['XDG_CACHE_HOME'], 'astropy')) | ||
|
||
# Note that we don't need to change the environment variables back or remove | ||
# them after testing, because they are only changed for the duration of the | ||
# Python process, and this configuration only matters if running pytest | ||
# directly, not from e.g. an IPython session. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed here but not in the other conftest files ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how I feel about playing with env var in general in
conftest
. Let's say user sets custom vars, then run tests,conftest
messes them up, now user complains that the these vars are not what they set anymore. Can this happen?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it's needed here and not in the other
conftest.py
files is because this is the only one which might be used inside a persistent python session such as IPython. The other ones will only matter if you runpytest
, and the Python process will end at the end of the tests. Any changes toos.environ
don't change the variables beyond the Python process:However, in this specific
conftest.py
file I should probably indeed save any pre-existing variables and reset then inunconfigure
.