~crunch.io/ubuntu/precise/codespeak-lib/unstable

« back to all changes in this revision

Viewing changes to py/_plugin/pytest_nose.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-08-01 16:24:01 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100801162401-g37v49d1p148alpm
Tags: 1.3.3-1
* New upstream release.
* Bump Standards-Version to 3.9.1.
* Fix typo in py.test manpage.
* Prefer Breaks: over Conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""nose-compatibility plugin: allow to run nose test suites natively. 
 
1
"""nose-compatibility plugin: allow to run nose test suites natively.
2
2
 
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.
5
5
 
6
6
Usage
7
7
-------------
11
11
    py.test  # instead of 'nosetests'
12
12
 
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.
15
15
 
16
16
Supported nose Idioms
17
17
----------------------
18
18
 
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
24
24
 
25
25
Unsupported idioms / issues
26
26
----------------------------------
27
27
 
28
28
- nose-style doctests are not collected and executed correctly,
29
 
  also fixtures don't work. 
30
 
 
31
 
- no nose-configuration is recognized 
32
 
 
33
 
If you find other issues or have suggestions please run:: 
34
 
 
35
 
    py.test --pastebin=all 
 
29
  also fixtures don't work.
 
30
 
 
31
- no nose-configuration is recognized
 
32
 
 
33
If you find other issues or have suggestions please run::
 
34
 
 
35
    py.test --pastebin=all
36
36
 
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.
39
39
"""
40
40
import py
41
41
import inspect
45
45
    SkipTest = getattr(sys.modules.get('nose', None), 'SkipTest', None)
46
46
    if SkipTest:
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
51
51
 
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):
56
56
        obj = item.obj
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"):
60
60
                fn = fn[:-1]
61
61
            #assert 0
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__
65
 
    
 
65
 
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):
69
 
            gen = item.parent 
 
69
            gen = item.parent
70
70
            if not hasattr(gen, '_nosegensetup'):
71
71
                call_optional(gen.obj, 'setup')
72
72
                if isinstance(gen.parent, py.test.collect.Instance):