Coverage for /usr/local/lib/python3.7/site-packages/_pytest/nose.py : 55%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1""" run test suites written for nose. """
2from _pytest import python
3from _pytest import unittest
4from _pytest.config import hookimpl
7@hookimpl(trylast=True)
8def pytest_runtest_setup(item):
9 if is_potential_nosetest(item):
10 if not call_optional(item.obj, "setup"):
11 # call module level setup if there is no object level one
12 call_optional(item.parent.obj, "setup")
13 # XXX this implies we only call teardown when setup worked
14 item.session._setupstate.addfinalizer((lambda: teardown_nose(item)), item)
17def teardown_nose(item):
18 if is_potential_nosetest(item):
19 if not call_optional(item.obj, "teardown"):
20 call_optional(item.parent.obj, "teardown")
23def is_potential_nosetest(item):
24 # extra check needed since we do not do nose style setup/teardown
25 # on direct unittest style classes
26 return isinstance(item, python.Function) and not isinstance(
27 item, unittest.TestCaseFunction
28 )
31def call_optional(obj, name):
32 method = getattr(obj, name, None)
33 isfixture = hasattr(method, "_pytestfixturefunction")
34 if method is not None and not isfixture and callable(method):
35 # If there's any problems allow the exception to raise rather than
36 # silently ignoring them
37 method()
38 return True