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

« back to all changes in this revision

Viewing changes to testing/test_session.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:
4
4
    def test_initsession(self, testdir, tmpdir):
5
5
        config = testdir.reparseconfig()
6
6
        session = config.initsession()
7
 
        assert session.config is config 
8
 
    
 
7
        assert session.config is config
 
8
 
9
9
    def test_basic_testitem_events(self, testdir):
10
10
        tfile = testdir.makepyfile("""
11
 
            def test_one(): 
 
11
            def test_one():
12
12
                pass
13
13
            def test_one_one():
14
14
                assert 0
21
21
        passed, skipped, failed = reprec.listoutcomes()
22
22
        assert len(skipped) == 0
23
23
        assert len(passed) == 1
24
 
        assert len(failed) == 3  
 
24
        assert len(failed) == 3
25
25
        assert failed[0].item.name == "test_one_one"
26
26
        assert failed[1].item.name == "test_other"
27
27
        assert failed[2].item.name == "test_two"
32
32
        col = colstarted[0].collector
33
33
        assert isinstance(col, py.test.collect.Module)
34
34
 
35
 
    def test_nested_import_error(self, testdir): 
 
35
    def test_nested_import_error(self, testdir):
36
36
        tfile = testdir.makepyfile("""
37
37
            import import_fails
38
38
            def test_this():
39
39
                assert import_fails.a == 1
40
40
        """, import_fails="""
41
 
            import does_not_work 
 
41
            import does_not_work
42
42
            a = 1
43
43
        """)
44
44
        reprec = testdir.inline_run(tfile)
45
45
        l = reprec.getfailedcollections()
46
 
        assert len(l) == 1 
 
46
        assert len(l) == 1
47
47
        out = l[0].longrepr.reprcrash.message
48
 
        assert out.find('does_not_work') != -1 
 
48
        assert out.find('does_not_work') != -1
49
49
 
50
 
    def test_raises_output(self, testdir): 
 
50
    def test_raises_output(self, testdir):
51
51
        reprec = testdir.inline_runsource("""
52
52
            import py
53
53
            def test_raises_doesnt():
56
56
        passed, skipped, failed = reprec.listoutcomes()
57
57
        assert len(failed) == 1
58
58
        out = failed[0].longrepr.reprcrash.message
59
 
        if not out.find("DID NOT RAISE") != -1: 
 
59
        if not out.find("DID NOT RAISE") != -1:
60
60
            print(out)
61
 
            py.test.fail("incorrect raises() output") 
 
61
            py.test.fail("incorrect raises() output")
62
62
 
63
 
    def test_generator_yields_None(self, testdir): 
 
63
    def test_generator_yields_None(self, testdir):
64
64
        reprec = testdir.inline_runsource("""
65
65
            def test_1():
66
 
                yield None 
 
66
                yield None
67
67
        """)
68
68
        failures = reprec.getfailedcollections()
69
69
        out = failures[0].longrepr.reprcrash.message
70
 
        i = out.find('TypeError') 
71
 
        assert i != -1 
 
70
        i = out.find('TypeError')
 
71
        assert i != -1
72
72
 
73
 
    def test_syntax_error_module(self, testdir): 
 
73
    def test_syntax_error_module(self, testdir):
74
74
        reprec = testdir.inline_runsource("this is really not python")
75
75
        l = reprec.getfailedcollections()
76
76
        assert len(l) == 1
77
 
        out = l[0].longrepr.reprcrash.message
 
77
        out = str(l[0].longrepr)
78
78
        assert out.find(str('not python')) != -1
79
79
 
80
 
    def test_exit_first_problem(self, testdir): 
 
80
    def test_exit_first_problem(self, testdir):
81
81
        reprec = testdir.inline_runsource("""
82
82
            def test_one(): assert 0
83
83
            def test_two(): assert 0
86
86
        assert failed == 1
87
87
        assert passed == skipped == 0
88
88
 
 
89
    def test_maxfail(self, testdir):
 
90
        reprec = testdir.inline_runsource("""
 
91
            def test_one(): assert 0
 
92
            def test_two(): assert 0
 
93
            def test_three(): assert 0
 
94
        """, '--maxfail=2')
 
95
        passed, skipped, failed = reprec.countoutcomes()
 
96
        assert failed == 2
 
97
        assert passed == skipped == 0
 
98
 
89
99
    def test_broken_repr(self, testdir):
90
100
        p = testdir.makepyfile("""
91
101
            import py
93
103
                foo=0
94
104
                def __repr__(self):
95
105
                    raise Exception("Ha Ha fooled you, I'm a broken repr().")
96
 
            
 
106
 
97
107
            class TestBrokenClass:
98
108
                def test_explicit_bad_repr(self):
99
109
                    t = BrokenRepr1()
100
110
                    py.test.raises(Exception, 'repr(t)')
101
 
                    
 
111
 
102
112
                def test_implicit_bad_repr1(self):
103
113
                    t = BrokenRepr1()
104
114
                    assert t.foo == 1
122
132
        reprec = testdir.inline_run(testdir.tmpdir)
123
133
        reports = reprec.getreports("pytest_collectreport")
124
134
        assert len(reports) == 1
125
 
        assert reports[0].skipped 
 
135
        assert reports[0].skipped
126
136
 
127
137
class TestNewSession(SessionTests):
128
138
 
129
 
    def test_order_of_execution(self, testdir): 
 
139
    def test_order_of_execution(self, testdir):
130
140
        reprec = testdir.inline_runsource("""
131
141
            l = []
132
142
            def test_1():
149
159
        passed, skipped, failed = reprec.countoutcomes()
150
160
        assert failed == skipped == 0
151
161
        assert passed == 7
152
 
        # also test listnames() here ... 
 
162
        # also test listnames() here ...
153
163
 
154
164
    def test_collect_only_with_various_situations(self, testdir):
155
165
        p = testdir.makepyfile(
163
173
 
164
174
                class TestY(TestX):
165
175
                    pass
166
 
            """, 
 
176
            """,
167
177
            test_two="""
168
178
                import py
169
179
                py.test.skip('xxx')
170
 
            """, 
 
180
            """,
171
181
            test_three="xxxdsadsadsadsa",
172
182
            __init__=""
173
183
        )
174
184
        reprec = testdir.inline_run('--collectonly', p.dirpath())
175
 
       
 
185
 
176
186
        itemstarted = reprec.getcalls("pytest_itemstart")
177
187
        assert len(itemstarted) == 3
178
 
        assert not reprec.getreports("pytest_runtest_logreport") 
 
188
        assert not reprec.getreports("pytest_runtest_logreport")
179
189
        started = reprec.getcalls("pytest_collectstart")
180
190
        finished = reprec.getreports("pytest_collectreport")
181
 
        assert len(started) == len(finished) 
182
 
        assert len(started) == 8 
 
191
        assert len(started) == len(finished)
 
192
        assert len(started) == 8
183
193
        colfail = [x for x in finished if x.failed]
184
194
        colskipped = [x for x in finished if x.skipped]
185
195
        assert len(colfail) == 1