-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
TST: Skipif decorator for matplotlib #18190 #18427
Conversation
262eacf
to
fb9c6e1
Compare
Codecov Report
@@ Coverage Diff @@
## master #18427 +/- ##
==========================================
- Coverage 91.35% 91.33% -0.02%
==========================================
Files 163 164 +1
Lines 49714 49735 +21
==========================================
+ Hits 45415 45426 +11
- Misses 4299 4309 +10
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18427 +/- ##
==========================================
+ Coverage 91.32% 91.33% +<.01%
==========================================
Files 163 164 +1
Lines 49798 49819 +21
==========================================
+ Hits 45479 45503 +24
+ Misses 4319 4316 -3
Continue to review full report at Codecov.
|
pandas/tests/util/test_util.py
Outdated
|
||
|
||
def test__safe_import(): | ||
from _pytest.monkeypatch import MonkeyPatch |
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.
What is _pytest? On mobile and can’t check easily.
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.
That reflects the package structure of pytest. However, I think this can be re-written another way as I'm reading more on how pytest plugins work. Let me re-push
https://holgerkrekel.net/2009/03/03/monkeypatching-in-unit-tests-done-right/
pandas/util/_test_decorators.py
Outdated
import sys | ||
version = getattr(sys.modules[mod_name], '__version__') | ||
if version: | ||
from pkg_resources import parse_version as pv |
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.
We typically use distutils but I think we require setup tools now so this is fine, right?
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.
Yes there is currently an entry for setuptools
in requirements_dev.txt
FWIW this was inspired by the current importorskip
implementation in pytest that these skip functions were using previously
I think if you merge in master, the CirclCI failure will go away. |
b63873d
to
1e055fb
Compare
@@ -0,0 +1,45 @@ | |||
import pytest | |||
|
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.
can you add some text as to the purpose of this module
return mod | ||
else: | ||
import sys | ||
version = getattr(sys.modules[mod_name], '__version__') |
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 would use LooseVersion here (as we use this elsewhere)
pandas/util/_test_decorators.py
Outdated
import pytest | ||
|
||
|
||
def _safe_import(mod_name, min_version=None): |
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.
this could replace pandas.util.testing.skip_if_no_package
as well (or maybe be an input to it)
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.
since this is already in a private module, you can name it safe_import
1e055fb
to
46a43d7
Compare
@jreback 3/4 of your suggested edits made. The only one I didn't do is replacing |
totally fine to do later just bringing it up |
13628df
to
6d7ff3c
Compare
pandas/tests/test_resample.py
Outdated
@@ -13,6 +13,7 @@ | |||
import pandas as pd | |||
import pandas.tseries.offsets as offsets | |||
import pandas.util.testing as tm | |||
from pandas.util._test_decorators import skip_if_no_mpl |
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.
can you write these as
import pandas.util._test_decorators as td
then use td.skip_if_no_mpl
I think a bit simpler
6d7ff3c
to
ffcbe0a
Compare
return True | ||
|
||
|
||
skip_if_no_mpl = pytest.mark.skipif(_skip_if_no_mpl(), |
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 recall some issues with custom markers (#16680).
Do you know if this will cause similar issues with the --strict
flag? Could you try pytest --collect-only --strict
and see if anything errors? We may be OK since it's a skipif
marker, which pytest already knows about...
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.
When running that locally I get one error that high_memory is not a registered marker
because pandas/tests/io/parser/c_parser_only.py
has @pytest.mark.high_memory
on line 21, but the registered marker is just @pytest.mark.highmemory
(no underscore). I believe that to be unrelated to the change here
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.
Oh, OK. I'll make a PR for the high_memory issue. Thanks!
git diff upstream/master -u -- "*.py" | flake8 --diff
The behavior here is slightly different than before when the function was used at the module level. Previously, an entire module being skipped would count as one skip entry. Now with the decorator, each test case within the module gets counted as a skip.