1
"""nose-compatibility plugin: allow to run nose test suites natively.
1
"""nose-compatibility plugin: allow to run nose test suites natively.
3
This is an experimental plugin for allowing to run tests written
4
in 'nosetests style with py.test.
3
This is an experimental plugin for allowing to run tests written
4
in 'nosetests style with py.test.
11
11
py.test # instead of 'nosetests'
13
13
and you should be able to run nose style tests and at the same
14
time can make full use of py.test's capabilities.
14
time can make full use of py.test's capabilities.
16
16
Supported nose Idioms
17
17
----------------------
19
19
* setup and teardown at module/class/method level
20
* SkipTest exceptions and markers
20
* SkipTest exceptions and markers
21
21
* setup/teardown decorators
22
* yield-based tests and their setup
23
* general usage of nose utilities
22
* yield-based tests and their setup
23
* general usage of nose utilities
25
25
Unsupported idioms / issues
26
26
----------------------------------
28
28
- nose-style doctests are not collected and executed correctly,
29
also fixtures don't work.
31
- no nose-configuration is recognized
33
If you find other issues or have suggestions please run::
35
py.test --pastebin=all
29
also fixtures don't work.
31
- no nose-configuration is recognized
33
If you find other issues or have suggestions please run::
35
py.test --pastebin=all
37
37
and send the resulting URL to a py.test contact channel,
38
at best to the mailing list.
38
at best to the mailing list.
45
45
SkipTest = getattr(sys.modules.get('nose', None), 'SkipTest', None)
47
47
if call.excinfo and call.excinfo.errisinstance(SkipTest):
48
# let's substitute the excinfo with a py.test.skip one
48
# let's substitute the excinfo with a py.test.skip one
49
49
call2 = call.__class__(lambda: py.test.skip(str(call.excinfo.value)), call.when)
50
call.excinfo = call2.excinfo
50
call.excinfo = call2.excinfo
52
52
def pytest_report_iteminfo(item):
53
# nose 0.11.1 uses decorators for "raises" and other helpers.
54
# for reporting progress by filename we fish for the filename
53
# nose 0.11.1 uses decorators for "raises" and other helpers.
54
# for reporting progress by filename we fish for the filename
55
55
if isinstance(item, py.test.collect.Function):
57
57
if hasattr(obj, 'compat_co_firstlineno'):
58
fn = sys.modules[obj.__module__].__file__
58
fn = sys.modules[obj.__module__].__file__
59
59
if fn.endswith(".pyc"):
62
62
#fn = inspect.getsourcefile(obj) or inspect.getfile(obj)
63
lineno = obj.compat_co_firstlineno
63
lineno = obj.compat_co_firstlineno
64
64
return py.path.local(fn), lineno, obj.__module__
66
66
def pytest_runtest_setup(item):
67
67
if isinstance(item, (py.test.collect.Function)):
68
68
if isinstance(item.parent, py.test.collect.Generator):
70
70
if not hasattr(gen, '_nosegensetup'):
71
71
call_optional(gen.obj, 'setup')
72
72
if isinstance(gen.parent, py.test.collect.Instance):