def test_setup_fails_and_failure_is_cached(self, testdir): item = testdir.getitem(""" def setup_module(mod): raise ValueError(42) def test_func(): pass """) # noqa ss = runner.SetupState() pytest.raises(ValueError, lambda: ss.prepare(item)) pytest.raises(ValueError, lambda: ss.prepare(item))
def test_setup(self, testdir): ss = runner.SetupState() item = testdir.getitem("def test_func(): pass") l = [1] ss.prepare(item) ss.addfinalizer(l.pop, colitem=item) assert l ss._pop_and_teardown() assert not l
def test_setup(self, testdir) -> None: ss = runner.SetupState() item = testdir.getitem("def test_func(): pass") values = [1] ss.prepare(item) ss.addfinalizer(values.pop, colitem=item) assert values ss._pop_and_teardown() assert not values
def test_teardown_multiple_fail(self, testdir): # Ensure the first exception is the one which is re-raised. # Ideally both would be reported however. def fin1(): raise Exception('oops1') def fin2(): raise Exception('oops2') item = testdir.getitem("def test_func(): pass") ss = runner.SetupState() ss.addfinalizer(fin1, item) ss.addfinalizer(fin2, item) with pytest.raises(Exception) as err: ss._callfinalizers(item) assert err.value.args == ('oops2',)
def test_setup_scope_None(self, testdir): item = testdir.getitem("def test_func(): pass") ss = runner.SetupState() l = [1] ss.prepare(item) ss.addfinalizer(l.pop, colitem=None) assert l ss._pop_and_teardown() assert l ss._pop_and_teardown() assert l ss.teardown_all() assert not l
def test_teardown_multiple_one_fails(self, testdir): r = [] def fin1(): r.append('fin1') def fin2(): raise Exception('oops') def fin3(): r.append('fin3') item = testdir.getitem("def test_func(): pass") ss = runner.SetupState() ss.addfinalizer(fin1, item) ss.addfinalizer(fin2, item) ss.addfinalizer(fin3, item) with pytest.raises(Exception) as err: ss._callfinalizers(item) assert err.value.args == ('oops',) assert r == ['fin3', 'fin1']
def test_teardown_multiple_scopes_one_fails(self, testdir): module_teardown = [] def fin_func(): raise Exception("oops1") def fin_module(): module_teardown.append("fin_module") item = testdir.getitem("def test_func(): pass") ss = runner.SetupState() ss.addfinalizer(fin_module, item.listchain()[-2]) ss.addfinalizer(fin_func, item) ss.prepare(item) with pytest.raises(Exception, match="oops1"): ss.teardown_exact(item, None) assert module_teardown
def test_teardown_multiple_one_fails(self, pytester: Pytester) -> None: r = [] def fin1(): r.append("fin1") def fin2(): raise Exception("oops") def fin3(): r.append("fin3") item = pytester.getitem("def test_func(): pass") ss = runner.SetupState() ss.addfinalizer(fin1, item) ss.addfinalizer(fin2, item) ss.addfinalizer(fin3, item) with pytest.raises(Exception) as err: ss._callfinalizers(item) assert err.value.args == ("oops", ) assert r == ["fin3", "fin1"]
def test_teardown_exact_stack_empty(self, testdir): item = testdir.getitem("def test_func(): pass") ss = runner.SetupState() ss.teardown_exact(item, None) ss.teardown_exact(item, None) ss.teardown_exact(item, None)
def test_teardown_exact_stack_empty(self, pytester: Pytester) -> None: item = pytester.getitem("def test_func(): pass") ss = runner.SetupState() ss.teardown_exact(item, None) ss.teardown_exact(item, None) ss.teardown_exact(item, None)