8000 Add Py.test testing framework support by Kojoley · Pull Request #6730 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add Py.test testing framework support #6730

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 10 commits into from
Aug 23, 2016
Merged
Prev Previous commit
Next Next commit
Implemented test filtering for pytest
  • Loading branch information
Kojoley committed Aug 21, 2016
commit 6c94b47c99730346ad4802739a9cda699beb0ff2
54 changes: 54 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,68 @@
unicode_literals)

import inspect
import os
import pytest
import unittest

import matplotlib
matplotlib.use('agg')

from matplotlib import default_test_modules
from matplotlib.testing.decorators import ImageComparisonTest


IGNORED_TESTS = {
'matplotlib': [
'test_usetex',
],
}


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 is_nose_class(cls):
"""Check if supplied class looks like Nose testcase"""
return any(name in ['setUp', 'tearDown']
for name, _ in inspect.getmembers(cls))


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')


def pytest_configure(config):
matplotlib._called_from_pytest = True

Expand All @@ -24,6 +72,12 @@ 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)


def pytest_pycollect_makeitem(collector, name, obj):
if inspect.isclass(obj):
if issubclass(obj, ImageComparisonTest):
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
norecursedirs = .git build ci dist extern release tools unit
0