Skip to content

Switch testing to pytest completely #7974

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

Merged
merged 14 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove pytest collection filter.
It's really only needed to get the pep8 options.
  • Loading branch information
QuLogic committed Feb 2, 2017
commit bd91b938e27c5ab7d47dcbb507bd948207e06aef
57 changes: 0 additions & 57 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,11 @@
import matplotlib
matplotlib.use('agg')

from matplotlib import default_test_modules


IGNORED_TESTS = {
'matplotlib': [],
}


def blacklist_check(path):
"""Check if test is blacklisted and should be ignored"""
head, tests_dir = os.path.split(path.dirname)
if tests_dir != 'tests':
return True
head, top_module = os.path.split(head)
return path.purebasename in IGNORED_TESTS.get(top_module, [])


def whitelist_check(path):
"""Check if test is not whitelisted and should be ignored"""
left = path.dirname
last_left = None
module_path = path.purebasename
while len(left) and left != last_left:
last_left = left
left, tail = os.path.split(left)
module_path = '.'.join([tail, module_path])
if module_path in default_test_modules:
return False
return True


COLLECT_FILTERS = {
'none': lambda _: False,
'blacklist': blacklist_check,
'whitelist': whitelist_check,
}


def pytest_addoption(parser):
group = parser.getgroup("matplotlib", "matplotlib custom options")

group.addoption('--collect-filter', action='store',
choices=COLLECT_FILTERS, default='blacklist',
help='filter tests during collection phase')

group.addoption('--no-pep8', action='store_true',
help='skip PEP8 compliance tests')


def pytest_configure(config):
matplotlib._called_from_pytest = True
matplotlib._init_tests()

if config.getoption('--no-pep8'):
IGNORED_TESTS['matplotlib'] += 'test_coding_standards'


def pytest_unconfigure(config):
matplotlib._called_from_pytest = False


def pytest_ignore_collect(path, config):
if path.ext == '.py':
collect_filter = config.getoption('--collect-filter')
return COLLECT_FILTERS[collect_filter](path)
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[pytest]
norecursedirs = .git build ci dist extern release tools unit venv
norecursedirs = .git build ci dist doc extern lib/mpl_examples release tools unit venv
python_files = test_*.py
pep8ignore =
* E111 E114 E115 E116 E121 E122 E123 E124 E125 E126 E127 E128 E129 E131 E226 E240 E241 E242 E243 E244 E245 E246 E247 E248 E249 E265 E266 E704 W503

Expand Down
6 changes: 3 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

# The warnings need to be before any of matplotlib imports, but after
# setuptools (if present) which has syntax error with the warnings enabled.
# Filtering by module does not work as this will be raised by Python itself.
# Filtering by module does not work as this will be raised by Python itself
# so `module=matplotlib.*` is out of questions.

import warnings

# Python 3.6 deprecate invalid character-pairs \A, \* ... in non raw-strings
# and other things. Let's not re-introduce them
# Python 3.6 deprecate invalid character-pairs \A, \* ... in non
# raw-strings and other things. Let's not re-introduce them
warnings.filterwarnings('error', '.*invalid escape sequence.*',
category=DeprecationWarning)
warnings.filterwarnings(
Expand Down