-
Notifications
You must be signed in to change notification settings - Fork 648
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
Import of Test Examples changes matplotlib backend #2191
Comments
Fair enough, but honestly I have been struggling to understand how to do this differently because matplotlib does not allow us to change the backend later. How can we ensure that our tests run with the agg backend and not with any of the GUI ones? |
We could do a pytest fixture that switches the backend to/from, something like: @pytest.fixture
def mpl():
curr = matplotlib.get_backend()
try:
matplotlib.use('agg')
yield
finally:
matplotlib.use(curr)
def test_plot(mpl):
# test with backend temporarily changed But matplotlib complains about the backend being set after pyplot import, so there's another step I'm missing. Maybe a forced reload of the package? |
We could set the backend when we import matplotlib in each test module that needs it, instead of doing the import at the package level in the init. It is not much of a problem if pytest changes the backend, the real issue is that the init changes it which mean we cannot safely import from |
Now I see where it comes from, as @jbarnoud says; the documentation is full of like examples. For example I stumbled upon this: |
The discussion above seems to suggest the backend adjustment is actually happening for the unit test infrastructure, rather than for the examples in docstrings. If the main reason for having some kind of top-level data module backend switch to agg is because of docstrings, we might consider using i.e., refguide_check.py instead of vanilla doctests, since the backend switch to Agg happens gracefully / automatically for doctesting that way. But if it is really unit tests that are the problem refguide doesn't solve the issue. Do we actually CI test our docstrings with vanilla doctest? I'd guess not--standard library doctest is a real pain for scientific code, which is why refguide was created. There's some interest in creating a third-party refguide library so that different packages don't keep vendoring the module. |
There's also |
We should get rid of mdanalysis/testsuite/MDAnalysisTests/__init__.py Lines 120 to 128 in 1f4e492
|
https://matplotlib.org/3.2.1/tutorials/introductory/usage.html#backends says that we can set export MPLBACKEND=agg in our CI environment and then that will overrule anything else. In particular, it allows us to get rid off |
- fix #2191 - use MPLBACKEND=agg in the CI environments - Travis - appveyor - Azure pipelines
- fix #2191 - use MPLBACKEND=agg in the CI environments - Travis - appveyor - Azure pipelines - update CHANGELOG
- fix #2191 - use MPLBACKEND=agg in the CI environments - Travis - appveyor - Azure pipelines - update CHANGELOG
- fix #2191 - use MPLBACKEND=agg in the CI environments - Travis - appveyor - Azure pipelines - update CHANGELOG
- fix #2191 - use MPLBACKEND=agg in the CI environments - Travis - appveyor - Azure pipelines - update CHANGELOG
The fix for this issue also removes the error (with matplotlib ≥ 3.3)
because the whole line is removed in in PR #2763 |
- fix MDAnalysis#2191 - use MPLBACKEND=agg in the CI environments - Travis - appveyor - Azure pipelines - update CHANGELOG
Expected behavior
Importing example datafiles should not affect matplotlib backend as with 'agg' bad things happen (cfr. [7])
Actual behavior
Currently version of MDAnalysis
The text was updated successfully, but these errors were encountered: