Exemplo n.º 1
0
 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"
Exemplo n.º 2
0
 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"
Exemplo n.º 3
0
 def test_longreprtext_pass(self, pytester: Pytester) -> None:
     reports = pytester.runitem("""
         def test_func():
             pass
     """)
     rep = reports[1]
     assert rep.longreprtext == ""
Exemplo n.º 4
0
    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"
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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 == ""
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 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"
Exemplo n.º 11
0
 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"
Exemplo n.º 12
0
 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"
Exemplo n.º 13
0
 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
Exemplo n.º 14
0
 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"
Exemplo n.º 15
0
 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
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
 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