Skip to content
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

Merged
merged 1 commit into from
Nov 27, 2017

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Nov 22, 2017

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.

@WillAyd WillAyd force-pushed the pd-test-decs branch 2 times, most recently from 262eacf to fb9c6e1 Compare November 22, 2017 18:02
@codecov
Copy link

codecov bot commented Nov 22, 2017

Codecov Report

Merging #18427 into master will decrease coverage by 0.01%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.13% <95.23%> (ø) ⬆️
#single 39.64% <52.38%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 100% <ø> (ø) ⬆️
pandas/util/_test_decorators.py 95.23% <95.23%> (ø)
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d421a09...fb9c6e1. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 22, 2017

Codecov Report

Merging #18427 into master will increase coverage by <.01%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.13% <95.23%> (+0.02%) ⬆️
#single 40.8% <52.38%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 100% <ø> (ø) ⬆️
pandas/util/_test_decorators.py 95.23% <95.23%> (ø)
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.81% <0%> (-0.1%) ⬇️
pandas/core/indexes/datetimes.py 95.71% <0%> (+0.09%) ⬆️
pandas/plotting/_converter.py 65.25% <0%> (+1.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 262e8ff...ffcbe0a. Read the comment docs.

@jreback jreback added the Testing pandas testing functions or related to the test suite label Nov 22, 2017
@jreback
Copy link
Contributor

jreback commented Nov 22, 2017

@TomAugspurger



def test__safe_import():
from _pytest.monkeypatch import MonkeyPatch
Copy link
Contributor

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.

Copy link
Member Author

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/

import sys
version = getattr(sys.modules[mod_name], '__version__')
if version:
from pkg_resources import parse_version as pv
Copy link
Contributor

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?

Copy link
Member Author

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

@TomAugspurger
Copy link
Contributor

I think if you merge in master, the CirclCI failure will go away.

@WillAyd WillAyd force-pushed the pd-test-decs branch 2 times, most recently from b63873d to 1e055fb Compare November 26, 2017 14:57
@@ -0,0 +1,45 @@
import pytest

Copy link
Contributor

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__')
Copy link
Contributor

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)

import pytest


def _safe_import(mod_name, min_version=None):
Copy link
Contributor

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)

Copy link
Contributor

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

@WillAyd
Copy link
Member Author

WillAyd commented Nov 26, 2017

@jreback 3/4 of your suggested edits made. The only one I didn't do is replacing pandas.util.testing.skip_if_no_package. Looking at that function, it is almost always used when looking for scipy dependencies (also saw one check for tables). You are correct that the safe_import method should be able to replace this, but I'd rather tackle that with the PR that converts the scipy skip functions into decorators rather than this change with mpl.

@jreback
Copy link
Contributor

jreback commented Nov 26, 2017

totally fine to do later just bringing it up

@WillAyd WillAyd force-pushed the pd-test-decs branch 2 times, most recently from 13628df to 6d7ff3c Compare November 26, 2017 22:01
@@ -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
Copy link
Contributor

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

@jreback
Copy link
Contributor

jreback commented Nov 27, 2017

@TomAugspurger

return True


skip_if_no_mpl = pytest.mark.skipif(_skip_if_no_mpl(),
Copy link
Contributor

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...

Copy link
Member Author

@WillAyd WillAyd Nov 27, 2017

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 markerbecause 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

Copy link
Contributor

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!

@TomAugspurger TomAugspurger merged commit 34b036c into pandas-dev:master Nov 27, 2017
@WillAyd WillAyd deleted the pd-test-decs branch November 27, 2017 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants