def test_keyboardinterrupt_propagates(self, pytester: Pytester) -> None: try: pytester.runitem(""" def test_func(): raise KeyboardInterrupt("fake") """) except KeyboardInterrupt: pass else: assert False, "did not raise"
def test_exit_propagates(self, pytester: Pytester) -> None: try: pytester.runitem(""" import pytest def test_func(): raise pytest.exit.Exception() """) except pytest.exit.Exception: pass else: assert False, "did not raise"
def test_longreprtext_pass(self, pytester: Pytester) -> None: reports = pytester.runitem(""" def test_func(): pass """) rep = reports[1] assert rep.longreprtext == ""
def test_captured_text(self, pytester: Pytester) -> None: reports = pytester.runitem(""" import pytest import sys @pytest.fixture def fix(): sys.stdout.write('setup: stdout\\n') sys.stderr.write('setup: stderr\\n') yield sys.stdout.write('teardown: stdout\\n') sys.stderr.write('teardown: stderr\\n') assert 0 def test_func(fix): sys.stdout.write('call: stdout\\n') sys.stderr.write('call: stderr\\n') assert 0 """) setup, call, teardown = reports assert setup.capstdout == "setup: stdout\n" assert call.capstdout == "setup: stdout\ncall: stdout\n" assert teardown.capstdout == "setup: stdout\ncall: stdout\nteardown: stdout\n" assert setup.capstderr == "setup: stderr\n" assert call.capstderr == "setup: stderr\ncall: stderr\n" assert teardown.capstderr == "setup: stderr\ncall: stderr\nteardown: stderr\n"
def test_longreprtext_failure(self, pytester: Pytester) -> None: reports = pytester.runitem(""" def test_func(): x = 1 assert x == 4 """) rep = reports[1] assert "assert 1 == 4" in rep.longreprtext
def test_no_captured_text(self, pytester: Pytester) -> None: reports = pytester.runitem(""" def test_func(): pass """) rep = reports[1] assert rep.capstdout == "" assert rep.capstderr == ""
def test_longrepr_type(self, pytester: Pytester) -> None: reports = pytester.runitem(""" import pytest def test_func(): pytest.fail(pytrace=False) """) rep = reports[1] assert isinstance(rep.longrepr, ExceptionChainRepr)
def test_passfunction(self, pytester: Pytester) -> None: reports = pytester.runitem(""" def test_func(): pass """) rep = reports[1] assert rep.passed assert not rep.failed assert rep.outcome == "passed" assert not rep.longrepr
def test_longreprtext_skip(self, pytester: Pytester) -> None: """TestReport.longreprtext can handle non-str ``longrepr`` attributes (#7559)""" reports = pytester.runitem(""" import pytest def test_func(): pytest.skip() """) _, call_rep, _ = reports assert isinstance(call_rep.longrepr, tuple) assert "Skipped" in call_rep.longreprtext
def test_systemexit_does_not_bail_out(self, pytester: Pytester) -> None: try: reports = pytester.runitem(""" def test_func(): raise SystemExit(42) """) except SystemExit: assert False, "runner did not catch SystemExit" rep = reports[1] assert rep.failed assert rep.when == "call"
def test_skipfunction(self, pytester: Pytester) -> None: reports = pytester.runitem(""" import pytest def test_func(): pytest.skip("hello") """) rep = reports[1] assert not rep.failed assert not rep.passed assert rep.skipped assert rep.outcome == "skipped"
def test_failfunction(self, pytester: Pytester) -> None: reports = pytester.runitem(""" def test_func(): assert 0 """) rep = reports[1] assert not rep.passed assert not rep.skipped assert rep.failed assert rep.when == "call" assert rep.outcome == "failed"
def test_failure_in_setup_function(self, pytester: Pytester) -> None: reports = pytester.runitem(""" import pytest def setup_function(func): raise ValueError(42) def test_func(): pass """) rep = reports[0] assert not rep.skipped assert not rep.passed assert rep.failed assert rep.when == "setup" assert len(reports) == 2
def test_failure_in_teardown_function(self, pytester: Pytester) -> None: reports = pytester.runitem(""" import pytest def teardown_function(func): raise ValueError(42) def test_func(): pass """) print(reports) assert len(reports) == 3 rep = reports[2] assert not rep.skipped assert not rep.passed assert rep.failed assert rep.when == "teardown"
def test_custom_failure_repr(self, pytester: Pytester) -> None: pytester.makepyfile(conftest=""" import pytest class Function(pytest.Function): def repr_failure(self, excinfo): return "hello" """) reports = pytester.runitem(""" import pytest def test_func(): assert 0 """) rep = reports[1] assert not rep.skipped assert not rep.passed assert rep.failed
def test_skip_in_setup_function(self, pytester: Pytester) -> None: reports = pytester.runitem(""" import pytest def setup_function(func): pytest.skip("hello") def test_func(): pass """) print(reports) rep = reports[0] assert not rep.failed assert not rep.passed assert rep.skipped # assert rep.skipped.reason == "hello" # assert rep.skipped.location.lineno == 3 # assert rep.skipped.location.lineno == 3 assert len(reports) == 2 assert reports[1].passed # teardown
def test_failure_in_setup_function_ignores_custom_repr( self, pytester: Pytester) -> None: pytester.makepyfile(conftest=""" import pytest class Function(pytest.Function): def repr_failure(self, excinfo): assert 0 """) reports = pytester.runitem(""" def setup_function(func): raise ValueError(42) def test_func(): pass """) assert len(reports) == 2 rep = reports[0] print(rep) assert not rep.skipped assert not rep.passed assert rep.failed