4
4
def test_initsession(self, testdir, tmpdir):
5
5
config = testdir.reparseconfig()
6
6
session = config.initsession()
7
assert session.config is config
7
assert session.config is config
9
9
def test_basic_testitem_events(self, testdir):
10
10
tfile = testdir.makepyfile("""
13
13
def test_one_one():
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)
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
39
39
assert import_fails.a == 1
40
40
""", import_fails="""
44
44
reprec = testdir.inline_run(tfile)
45
45
l = reprec.getfailedcollections()
47
47
out = l[0].longrepr.reprcrash.message
48
assert out.find('does_not_work') != -1
48
assert out.find('does_not_work') != -1
50
def test_raises_output(self, testdir):
50
def test_raises_output(self, testdir):
51
51
reprec = testdir.inline_runsource("""
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:
61
py.test.fail("incorrect raises() output")
61
py.test.fail("incorrect raises() output")
63
def test_generator_yields_None(self, testdir):
63
def test_generator_yields_None(self, testdir):
64
64
reprec = testdir.inline_runsource("""
68
68
failures = reprec.getfailedcollections()
69
69
out = failures[0].longrepr.reprcrash.message
70
i = out.find('TypeError')
70
i = out.find('TypeError')
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()
77
out = l[0].longrepr.reprcrash.message
77
out = str(l[0].longrepr)
78
78
assert out.find(str('not python')) != -1
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
87
87
assert passed == skipped == 0
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
95
passed, skipped, failed = reprec.countoutcomes()
97
assert passed == skipped == 0
89
99
def test_broken_repr(self, testdir):
90
100
p = testdir.makepyfile("""
94
104
def __repr__(self):
95
105
raise Exception("Ha Ha fooled you, I'm a broken repr().")
97
107
class TestBrokenClass:
98
108
def test_explicit_bad_repr(self):
100
110
py.test.raises(Exception, 'repr(t)')
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
127
137
class TestNewSession(SessionTests):
129
def test_order_of_execution(self, testdir):
139
def test_order_of_execution(self, testdir):
130
140
reprec = testdir.inline_runsource("""
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 ...
154
164
def test_collect_only_with_various_situations(self, testdir):
155
165
p = testdir.makepyfile(
164
174
class TestY(TestX):
169
179
py.test.skip('xxx')
171
181
test_three="xxxdsadsadsadsa",
174
184
reprec = testdir.inline_run('--collectonly', p.dirpath())
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