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
Prev Previous commit
Next Next commit
Add support of nose setup/teardown to pytest collector
  • Loading branch information
Kojoley committed Aug 21, 2016
commit af4afe2f6f92dc0074e16a4980ed6a8d42c0cfb6
23 changes: 23 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

import inspect
import pytest
import unittest

import matplotlib
matplotlib.use('agg')

from matplotlib.testing.decorators import ImageComparisonTest


def is_nose_class(cls):
return any(name in ['setUp', 'tearDown']
for name, _ in inspect.getmembers(cls))


def pytest_configure(config):
matplotlib._called_from_pytest = True

Expand All @@ -25,3 +31,20 @@ def pytest_pycollect_makeitem(collector, name, obj):
# instead of function and this confuses pytest because it crawls
# original names and sees 'test_*', but not 'Test*' in that case
return pytest.Class(name, parent=collector)

if is_nose_class(obj) and not issubclass(obj, unittest.TestCase):
# Workaround unittest-like setup/teardown names in pure classes
setup = getattr(obj, 'setUp', None)
if setup is not None:
obj.setup_method = lambda self, _: obj.setUp(self)
tearDown = getattr(obj, 'tearDown', None)
if tearDown is not None:
obj.teardown_method = lambda self, _: obj.tearDown(self)
setUpClass = getattr(obj, 'setUpClass', None)
if setUpClass is not None:
obj.setup_class = obj.setUpClass
tearDownClass = getattr(obj, 'tearDownClass', None)
if tearDownClass is not None:
obj.teardown_class = obj.tearDownClass

return pytest.Class(name, parent=collector)