Merge pull request #7970 from cmecklenborg/pytester_refactor_test_assertion
Migrate test_assertion.py from testdir to pytester
This commit is contained in:
		
						commit
						0cd190f037
					
				| 
						 | 
					@ -12,6 +12,7 @@ import pytest
 | 
				
			||||||
from _pytest import outcomes
 | 
					from _pytest import outcomes
 | 
				
			||||||
from _pytest.assertion import truncate
 | 
					from _pytest.assertion import truncate
 | 
				
			||||||
from _pytest.assertion import util
 | 
					from _pytest.assertion import util
 | 
				
			||||||
 | 
					from _pytest.pytester import Pytester
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def mock_config(verbose=0):
 | 
					def mock_config(verbose=0):
 | 
				
			||||||
| 
						 | 
					@ -27,9 +28,12 @@ def mock_config(verbose=0):
 | 
				
			||||||
class TestImportHookInstallation:
 | 
					class TestImportHookInstallation:
 | 
				
			||||||
    @pytest.mark.parametrize("initial_conftest", [True, False])
 | 
					    @pytest.mark.parametrize("initial_conftest", [True, False])
 | 
				
			||||||
    @pytest.mark.parametrize("mode", ["plain", "rewrite"])
 | 
					    @pytest.mark.parametrize("mode", ["plain", "rewrite"])
 | 
				
			||||||
    def test_conftest_assertion_rewrite(self, testdir, initial_conftest, mode):
 | 
					    def test_conftest_assertion_rewrite(
 | 
				
			||||||
 | 
					        self, pytester: Pytester, initial_conftest, mode
 | 
				
			||||||
 | 
					    ) -> None:
 | 
				
			||||||
        """Test that conftest files are using assertion rewrite on import (#1619)."""
 | 
					        """Test that conftest files are using assertion rewrite on import (#1619)."""
 | 
				
			||||||
        testdir.tmpdir.join("foo/tests").ensure(dir=1)
 | 
					        pytester.mkdir("foo")
 | 
				
			||||||
 | 
					        pytester.mkdir("foo/tests")
 | 
				
			||||||
        conftest_path = "conftest.py" if initial_conftest else "foo/conftest.py"
 | 
					        conftest_path = "conftest.py" if initial_conftest else "foo/conftest.py"
 | 
				
			||||||
        contents = {
 | 
					        contents = {
 | 
				
			||||||
            conftest_path: """
 | 
					            conftest_path: """
 | 
				
			||||||
| 
						 | 
					@ -45,8 +49,8 @@ class TestImportHookInstallation:
 | 
				
			||||||
                    check_first([10, 30], 30)
 | 
					                    check_first([10, 30], 30)
 | 
				
			||||||
            """,
 | 
					            """,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        testdir.makepyfile(**contents)
 | 
					        pytester.makepyfile(**contents)
 | 
				
			||||||
        result = testdir.runpytest_subprocess("--assert=%s" % mode)
 | 
					        result = pytester.runpytest_subprocess("--assert=%s" % mode)
 | 
				
			||||||
        if mode == "plain":
 | 
					        if mode == "plain":
 | 
				
			||||||
            expected = "E       AssertionError"
 | 
					            expected = "E       AssertionError"
 | 
				
			||||||
        elif mode == "rewrite":
 | 
					        elif mode == "rewrite":
 | 
				
			||||||
| 
						 | 
					@ -55,21 +59,21 @@ class TestImportHookInstallation:
 | 
				
			||||||
            assert 0
 | 
					            assert 0
 | 
				
			||||||
        result.stdout.fnmatch_lines([expected])
 | 
					        result.stdout.fnmatch_lines([expected])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_rewrite_assertions_pytester_plugin(self, testdir):
 | 
					    def test_rewrite_assertions_pytester_plugin(self, pytester: Pytester) -> None:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Assertions in the pytester plugin must also benefit from assertion
 | 
					        Assertions in the pytester plugin must also benefit from assertion
 | 
				
			||||||
        rewriting (#1920).
 | 
					        rewriting (#1920).
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        testdir.makepyfile(
 | 
					        pytester.makepyfile(
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            pytest_plugins = ['pytester']
 | 
					            pytest_plugins = ['pytester']
 | 
				
			||||||
            def test_dummy_failure(testdir):  # how meta!
 | 
					            def test_dummy_failure(pytester):  # how meta!
 | 
				
			||||||
                testdir.makepyfile('def test(): assert 0')
 | 
					                pytester.makepyfile('def test(): assert 0')
 | 
				
			||||||
                r = testdir.inline_run()
 | 
					                r = pytester.inline_run()
 | 
				
			||||||
                r.assertoutcome(passed=1)
 | 
					                r.assertoutcome(passed=1)
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        result = testdir.runpytest_subprocess()
 | 
					        result = pytester.runpytest_subprocess()
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
                ">       r.assertoutcome(passed=1)",
 | 
					                ">       r.assertoutcome(passed=1)",
 | 
				
			||||||
| 
						 | 
					@ -89,7 +93,7 @@ class TestImportHookInstallation:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.parametrize("mode", ["plain", "rewrite"])
 | 
					    @pytest.mark.parametrize("mode", ["plain", "rewrite"])
 | 
				
			||||||
    def test_pytest_plugins_rewrite(self, testdir, mode):
 | 
					    def test_pytest_plugins_rewrite(self, pytester: Pytester, mode) -> None:
 | 
				
			||||||
        contents = {
 | 
					        contents = {
 | 
				
			||||||
            "conftest.py": """
 | 
					            "conftest.py": """
 | 
				
			||||||
                pytest_plugins = ['ham']
 | 
					                pytest_plugins = ['ham']
 | 
				
			||||||
| 
						 | 
					@ -107,8 +111,8 @@ class TestImportHookInstallation:
 | 
				
			||||||
                    check_first([10, 30], 30)
 | 
					                    check_first([10, 30], 30)
 | 
				
			||||||
            """,
 | 
					            """,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        testdir.makepyfile(**contents)
 | 
					        pytester.makepyfile(**contents)
 | 
				
			||||||
        result = testdir.runpytest_subprocess("--assert=%s" % mode)
 | 
					        result = pytester.runpytest_subprocess("--assert=%s" % mode)
 | 
				
			||||||
        if mode == "plain":
 | 
					        if mode == "plain":
 | 
				
			||||||
            expected = "E       AssertionError"
 | 
					            expected = "E       AssertionError"
 | 
				
			||||||
        elif mode == "rewrite":
 | 
					        elif mode == "rewrite":
 | 
				
			||||||
| 
						 | 
					@ -118,7 +122,9 @@ class TestImportHookInstallation:
 | 
				
			||||||
        result.stdout.fnmatch_lines([expected])
 | 
					        result.stdout.fnmatch_lines([expected])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.parametrize("mode", ["str", "list"])
 | 
					    @pytest.mark.parametrize("mode", ["str", "list"])
 | 
				
			||||||
    def test_pytest_plugins_rewrite_module_names(self, testdir, mode):
 | 
					    def test_pytest_plugins_rewrite_module_names(
 | 
				
			||||||
 | 
					        self, pytester: Pytester, mode
 | 
				
			||||||
 | 
					    ) -> None:
 | 
				
			||||||
        """Test that pluginmanager correct marks pytest_plugins variables
 | 
					        """Test that pluginmanager correct marks pytest_plugins variables
 | 
				
			||||||
        for assertion rewriting if they are defined as plain strings or
 | 
					        for assertion rewriting if they are defined as plain strings or
 | 
				
			||||||
        list of strings (#1888).
 | 
					        list of strings (#1888).
 | 
				
			||||||
| 
						 | 
					@ -138,11 +144,13 @@ class TestImportHookInstallation:
 | 
				
			||||||
                    assert 'ham' in pytestconfig.pluginmanager.rewrite_hook._must_rewrite
 | 
					                    assert 'ham' in pytestconfig.pluginmanager.rewrite_hook._must_rewrite
 | 
				
			||||||
            """,
 | 
					            """,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        testdir.makepyfile(**contents)
 | 
					        pytester.makepyfile(**contents)
 | 
				
			||||||
        result = testdir.runpytest_subprocess("--assert=rewrite")
 | 
					        result = pytester.runpytest_subprocess("--assert=rewrite")
 | 
				
			||||||
        assert result.ret == 0
 | 
					        assert result.ret == 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_pytest_plugins_rewrite_module_names_correctly(self, testdir):
 | 
					    def test_pytest_plugins_rewrite_module_names_correctly(
 | 
				
			||||||
 | 
					        self, pytester: Pytester
 | 
				
			||||||
 | 
					    ) -> None:
 | 
				
			||||||
        """Test that we match files correctly when they are marked for rewriting (#2939)."""
 | 
					        """Test that we match files correctly when they are marked for rewriting (#2939)."""
 | 
				
			||||||
        contents = {
 | 
					        contents = {
 | 
				
			||||||
            "conftest.py": """\
 | 
					            "conftest.py": """\
 | 
				
			||||||
| 
						 | 
					@ -156,16 +164,18 @@ class TestImportHookInstallation:
 | 
				
			||||||
                    assert pytestconfig.pluginmanager.rewrite_hook.find_spec('hamster') is None
 | 
					                    assert pytestconfig.pluginmanager.rewrite_hook.find_spec('hamster') is None
 | 
				
			||||||
            """,
 | 
					            """,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        testdir.makepyfile(**contents)
 | 
					        pytester.makepyfile(**contents)
 | 
				
			||||||
        result = testdir.runpytest_subprocess("--assert=rewrite")
 | 
					        result = pytester.runpytest_subprocess("--assert=rewrite")
 | 
				
			||||||
        assert result.ret == 0
 | 
					        assert result.ret == 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.parametrize("mode", ["plain", "rewrite"])
 | 
					    @pytest.mark.parametrize("mode", ["plain", "rewrite"])
 | 
				
			||||||
    def test_installed_plugin_rewrite(self, testdir, mode, monkeypatch):
 | 
					    def test_installed_plugin_rewrite(
 | 
				
			||||||
 | 
					        self, pytester: Pytester, mode, monkeypatch
 | 
				
			||||||
 | 
					    ) -> None:
 | 
				
			||||||
        monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)
 | 
					        monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)
 | 
				
			||||||
        # Make sure the hook is installed early enough so that plugins
 | 
					        # Make sure the hook is installed early enough so that plugins
 | 
				
			||||||
        # installed via setuptools are rewritten.
 | 
					        # installed via setuptools are rewritten.
 | 
				
			||||||
        testdir.tmpdir.join("hampkg").ensure(dir=1)
 | 
					        pytester.mkdir("hampkg")
 | 
				
			||||||
        contents = {
 | 
					        contents = {
 | 
				
			||||||
            "hampkg/__init__.py": """\
 | 
					            "hampkg/__init__.py": """\
 | 
				
			||||||
                import pytest
 | 
					                import pytest
 | 
				
			||||||
| 
						 | 
					@ -219,8 +229,8 @@ class TestImportHookInstallation:
 | 
				
			||||||
                check_first([10, 30], 30)
 | 
					                check_first([10, 30], 30)
 | 
				
			||||||
            """,
 | 
					            """,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        testdir.makepyfile(**contents)
 | 
					        pytester.makepyfile(**contents)
 | 
				
			||||||
        result = testdir.run(
 | 
					        result = pytester.run(
 | 
				
			||||||
            sys.executable, "mainwrapper.py", "-s", "--assert=%s" % mode
 | 
					            sys.executable, "mainwrapper.py", "-s", "--assert=%s" % mode
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        if mode == "plain":
 | 
					        if mode == "plain":
 | 
				
			||||||
| 
						 | 
					@ -231,8 +241,8 @@ class TestImportHookInstallation:
 | 
				
			||||||
            assert 0
 | 
					            assert 0
 | 
				
			||||||
        result.stdout.fnmatch_lines([expected])
 | 
					        result.stdout.fnmatch_lines([expected])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_rewrite_ast(self, testdir):
 | 
					    def test_rewrite_ast(self, pytester: Pytester) -> None:
 | 
				
			||||||
        testdir.tmpdir.join("pkg").ensure(dir=1)
 | 
					        pytester.mkdir("pkg")
 | 
				
			||||||
        contents = {
 | 
					        contents = {
 | 
				
			||||||
            "pkg/__init__.py": """
 | 
					            "pkg/__init__.py": """
 | 
				
			||||||
                import pytest
 | 
					                import pytest
 | 
				
			||||||
| 
						 | 
					@ -265,8 +275,8 @@ class TestImportHookInstallation:
 | 
				
			||||||
                    pkg.other.tool()
 | 
					                    pkg.other.tool()
 | 
				
			||||||
            """,
 | 
					            """,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        testdir.makepyfile(**contents)
 | 
					        pytester.makepyfile(**contents)
 | 
				
			||||||
        result = testdir.runpytest_subprocess("--assert=rewrite")
 | 
					        result = pytester.runpytest_subprocess("--assert=rewrite")
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
                ">*assert a == b*",
 | 
					                ">*assert a == b*",
 | 
				
			||||||
| 
						 | 
					@ -285,8 +295,8 @@ class TestImportHookInstallation:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestBinReprIntegration:
 | 
					class TestBinReprIntegration:
 | 
				
			||||||
    def test_pytest_assertrepr_compare_called(self, testdir):
 | 
					    def test_pytest_assertrepr_compare_called(self, pytester: Pytester) -> None:
 | 
				
			||||||
        testdir.makeconftest(
 | 
					        pytester.makeconftest(
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            import pytest
 | 
					            import pytest
 | 
				
			||||||
            values = []
 | 
					            values = []
 | 
				
			||||||
| 
						 | 
					@ -298,7 +308,7 @@ class TestBinReprIntegration:
 | 
				
			||||||
                return values
 | 
					                return values
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        testdir.makepyfile(
 | 
					        pytester.makepyfile(
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            def test_hello():
 | 
					            def test_hello():
 | 
				
			||||||
                assert 0 == 1
 | 
					                assert 0 == 1
 | 
				
			||||||
| 
						 | 
					@ -306,7 +316,7 @@ class TestBinReprIntegration:
 | 
				
			||||||
                assert list == [("==", 0, 1)]
 | 
					                assert list == [("==", 0, 1)]
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        result = testdir.runpytest("-v")
 | 
					        result = pytester.runpytest("-v")
 | 
				
			||||||
        result.stdout.fnmatch_lines(["*test_hello*FAIL*", "*test_check*PASS*"])
 | 
					        result.stdout.fnmatch_lines(["*test_hello*FAIL*", "*test_check*PASS*"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -320,7 +330,7 @@ def callequal(left: Any, right: Any, verbose: int = 0) -> Optional[List[str]]:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestAssert_reprcompare:
 | 
					class TestAssert_reprcompare:
 | 
				
			||||||
    def test_different_types(self):
 | 
					    def test_different_types(self) -> None:
 | 
				
			||||||
        assert callequal([0, 1], "foo") is None
 | 
					        assert callequal([0, 1], "foo") is None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_summary(self) -> None:
 | 
					    def test_summary(self) -> None:
 | 
				
			||||||
| 
						 | 
					@ -329,7 +339,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
        summary = lines[0]
 | 
					        summary = lines[0]
 | 
				
			||||||
        assert len(summary) < 65
 | 
					        assert len(summary) < 65
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_text_diff(self):
 | 
					    def test_text_diff(self) -> None:
 | 
				
			||||||
        assert callequal("spam", "eggs") == [
 | 
					        assert callequal("spam", "eggs") == [
 | 
				
			||||||
            "'spam' == 'eggs'",
 | 
					            "'spam' == 'eggs'",
 | 
				
			||||||
            "- eggs",
 | 
					            "- eggs",
 | 
				
			||||||
| 
						 | 
					@ -357,7 +367,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
        assert "- eggs" in diff
 | 
					        assert "- eggs" in diff
 | 
				
			||||||
        assert "+ spam" in diff
 | 
					        assert "+ spam" in diff
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_bytes_diff_normal(self):
 | 
					    def test_bytes_diff_normal(self) -> None:
 | 
				
			||||||
        """Check special handling for bytes diff (#5260)"""
 | 
					        """Check special handling for bytes diff (#5260)"""
 | 
				
			||||||
        diff = callequal(b"spam", b"eggs")
 | 
					        diff = callequal(b"spam", b"eggs")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -367,7 +377,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
            "Use -v to get the full diff",
 | 
					            "Use -v to get the full diff",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_bytes_diff_verbose(self):
 | 
					    def test_bytes_diff_verbose(self) -> None:
 | 
				
			||||||
        """Check special handling for bytes diff (#5260)"""
 | 
					        """Check special handling for bytes diff (#5260)"""
 | 
				
			||||||
        diff = callequal(b"spam", b"eggs", verbose=1)
 | 
					        diff = callequal(b"spam", b"eggs", verbose=1)
 | 
				
			||||||
        assert diff == [
 | 
					        assert diff == [
 | 
				
			||||||
| 
						 | 
					@ -445,7 +455,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
        assert expl is not None
 | 
					        assert expl is not None
 | 
				
			||||||
        assert len(expl) > 1
 | 
					        assert len(expl) > 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_list_wrap_for_multiple_lines(self):
 | 
					    def test_list_wrap_for_multiple_lines(self) -> None:
 | 
				
			||||||
        long_d = "d" * 80
 | 
					        long_d = "d" * 80
 | 
				
			||||||
        l1 = ["a", "b", "c"]
 | 
					        l1 = ["a", "b", "c"]
 | 
				
			||||||
        l2 = ["a", "b", "c", long_d]
 | 
					        l2 = ["a", "b", "c", long_d]
 | 
				
			||||||
| 
						 | 
					@ -475,7 +485,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
            "  ]",
 | 
					            "  ]",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_list_wrap_for_width_rewrap_same_length(self):
 | 
					    def test_list_wrap_for_width_rewrap_same_length(self) -> None:
 | 
				
			||||||
        long_a = "a" * 30
 | 
					        long_a = "a" * 30
 | 
				
			||||||
        long_b = "b" * 30
 | 
					        long_b = "b" * 30
 | 
				
			||||||
        long_c = "c" * 30
 | 
					        long_c = "c" * 30
 | 
				
			||||||
| 
						 | 
					@ -494,7 +504,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
            "  ]",
 | 
					            "  ]",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_list_dont_wrap_strings(self):
 | 
					    def test_list_dont_wrap_strings(self) -> None:
 | 
				
			||||||
        long_a = "a" * 10
 | 
					        long_a = "a" * 10
 | 
				
			||||||
        l1 = ["a"] + [long_a for _ in range(0, 7)]
 | 
					        l1 = ["a"] + [long_a for _ in range(0, 7)]
 | 
				
			||||||
        l2 = ["should not get wrapped"]
 | 
					        l2 = ["should not get wrapped"]
 | 
				
			||||||
| 
						 | 
					@ -517,7 +527,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
            "  ]",
 | 
					            "  ]",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_dict_wrap(self):
 | 
					    def test_dict_wrap(self) -> None:
 | 
				
			||||||
        d1 = {"common": 1, "env": {"env1": 1, "env2": 2}}
 | 
					        d1 = {"common": 1, "env": {"env1": 1, "env2": 2}}
 | 
				
			||||||
        d2 = {"common": 1, "env": {"env1": 1}}
 | 
					        d2 = {"common": 1, "env": {"env1": 1}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -581,7 +591,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
        assert "Omitting" not in lines[1]
 | 
					        assert "Omitting" not in lines[1]
 | 
				
			||||||
        assert lines[2] == "{'b': 1}"
 | 
					        assert lines[2] == "{'b': 1}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_dict_different_items(self):
 | 
					    def test_dict_different_items(self) -> None:
 | 
				
			||||||
        lines = callequal({"a": 0}, {"b": 1, "c": 2}, verbose=2)
 | 
					        lines = callequal({"a": 0}, {"b": 1, "c": 2}, verbose=2)
 | 
				
			||||||
        assert lines == [
 | 
					        assert lines == [
 | 
				
			||||||
            "{'a': 0} == {'b': 1, 'c': 2}",
 | 
					            "{'a': 0} == {'b': 1, 'c': 2}",
 | 
				
			||||||
| 
						 | 
					@ -605,7 +615,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
            "+ {'b': 1, 'c': 2}",
 | 
					            "+ {'b': 1, 'c': 2}",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_sequence_different_items(self):
 | 
					    def test_sequence_different_items(self) -> None:
 | 
				
			||||||
        lines = callequal((1, 2), (3, 4, 5), verbose=2)
 | 
					        lines = callequal((1, 2), (3, 4, 5), verbose=2)
 | 
				
			||||||
        assert lines == [
 | 
					        assert lines == [
 | 
				
			||||||
            "(1, 2) == (3, 4, 5)",
 | 
					            "(1, 2) == (3, 4, 5)",
 | 
				
			||||||
| 
						 | 
					@ -714,7 +724,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
            " Probably an object has a faulty __repr__.)",
 | 
					            " Probably an object has a faulty __repr__.)",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_one_repr_empty(self):
 | 
					    def test_one_repr_empty(self) -> None:
 | 
				
			||||||
        """The faulty empty string repr did trigger an unbound local error in _diff_text."""
 | 
					        """The faulty empty string repr did trigger an unbound local error in _diff_text."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class A(str):
 | 
					        class A(str):
 | 
				
			||||||
| 
						 | 
					@ -729,14 +739,14 @@ class TestAssert_reprcompare:
 | 
				
			||||||
        assert expl is not None
 | 
					        assert expl is not None
 | 
				
			||||||
        assert "raised in repr()" not in " ".join(expl)
 | 
					        assert "raised in repr()" not in " ".join(expl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_unicode(self):
 | 
					    def test_unicode(self) -> None:
 | 
				
			||||||
        assert callequal("£€", "£") == [
 | 
					        assert callequal("£€", "£") == [
 | 
				
			||||||
            "'£€' == '£'",
 | 
					            "'£€' == '£'",
 | 
				
			||||||
            "- £",
 | 
					            "- £",
 | 
				
			||||||
            "+ £€",
 | 
					            "+ £€",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_nonascii_text(self):
 | 
					    def test_nonascii_text(self) -> None:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        :issue: 877
 | 
					        :issue: 877
 | 
				
			||||||
        non ascii python2 str caused a UnicodeDecodeError
 | 
					        non ascii python2 str caused a UnicodeDecodeError
 | 
				
			||||||
| 
						 | 
					@ -749,7 +759,7 @@ class TestAssert_reprcompare:
 | 
				
			||||||
        expl = callequal(A(), "1")
 | 
					        expl = callequal(A(), "1")
 | 
				
			||||||
        assert expl == ["ÿ == '1'", "- 1"]
 | 
					        assert expl == ["ÿ == '1'", "- 1"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_format_nonascii_explanation(self):
 | 
					    def test_format_nonascii_explanation(self) -> None:
 | 
				
			||||||
        assert util.format_explanation("λ")
 | 
					        assert util.format_explanation("λ")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_mojibake(self) -> None:
 | 
					    def test_mojibake(self) -> None:
 | 
				
			||||||
| 
						 | 
					@ -766,9 +776,9 @@ class TestAssert_reprcompare:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestAssert_reprcompare_dataclass:
 | 
					class TestAssert_reprcompare_dataclass:
 | 
				
			||||||
    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
					    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
				
			||||||
    def test_dataclasses(self, testdir):
 | 
					    def test_dataclasses(self, pytester: Pytester) -> None:
 | 
				
			||||||
        p = testdir.copy_example("dataclasses/test_compare_dataclasses.py")
 | 
					        p = pytester.copy_example("dataclasses/test_compare_dataclasses.py")
 | 
				
			||||||
        result = testdir.runpytest(p)
 | 
					        result = pytester.runpytest(p)
 | 
				
			||||||
        result.assert_outcomes(failed=1, passed=0)
 | 
					        result.assert_outcomes(failed=1, passed=0)
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
| 
						 | 
					@ -785,9 +795,9 @@ class TestAssert_reprcompare_dataclass:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
					    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
				
			||||||
    def test_recursive_dataclasses(self, testdir):
 | 
					    def test_recursive_dataclasses(self, pytester: Pytester) -> None:
 | 
				
			||||||
        p = testdir.copy_example("dataclasses/test_compare_recursive_dataclasses.py")
 | 
					        p = pytester.copy_example("dataclasses/test_compare_recursive_dataclasses.py")
 | 
				
			||||||
        result = testdir.runpytest(p)
 | 
					        result = pytester.runpytest(p)
 | 
				
			||||||
        result.assert_outcomes(failed=1, passed=0)
 | 
					        result.assert_outcomes(failed=1, passed=0)
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
| 
						 | 
					@ -804,9 +814,9 @@ class TestAssert_reprcompare_dataclass:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
					    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
				
			||||||
    def test_recursive_dataclasses_verbose(self, testdir):
 | 
					    def test_recursive_dataclasses_verbose(self, pytester: Pytester) -> None:
 | 
				
			||||||
        p = testdir.copy_example("dataclasses/test_compare_recursive_dataclasses.py")
 | 
					        p = pytester.copy_example("dataclasses/test_compare_recursive_dataclasses.py")
 | 
				
			||||||
        result = testdir.runpytest(p, "-vv")
 | 
					        result = pytester.runpytest(p, "-vv")
 | 
				
			||||||
        result.assert_outcomes(failed=1, passed=0)
 | 
					        result.assert_outcomes(failed=1, passed=0)
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
| 
						 | 
					@ -837,9 +847,9 @@ class TestAssert_reprcompare_dataclass:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
					    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
				
			||||||
    def test_dataclasses_verbose(self, testdir):
 | 
					    def test_dataclasses_verbose(self, pytester: Pytester) -> None:
 | 
				
			||||||
        p = testdir.copy_example("dataclasses/test_compare_dataclasses_verbose.py")
 | 
					        p = pytester.copy_example("dataclasses/test_compare_dataclasses_verbose.py")
 | 
				
			||||||
        result = testdir.runpytest(p, "-vv")
 | 
					        result = pytester.runpytest(p, "-vv")
 | 
				
			||||||
        result.assert_outcomes(failed=1, passed=0)
 | 
					        result.assert_outcomes(failed=1, passed=0)
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
| 
						 | 
					@ -851,19 +861,21 @@ class TestAssert_reprcompare_dataclass:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
					    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
				
			||||||
    def test_dataclasses_with_attribute_comparison_off(self, testdir):
 | 
					    def test_dataclasses_with_attribute_comparison_off(
 | 
				
			||||||
        p = testdir.copy_example(
 | 
					        self, pytester: Pytester
 | 
				
			||||||
 | 
					    ) -> None:
 | 
				
			||||||
 | 
					        p = pytester.copy_example(
 | 
				
			||||||
            "dataclasses/test_compare_dataclasses_field_comparison_off.py"
 | 
					            "dataclasses/test_compare_dataclasses_field_comparison_off.py"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        result = testdir.runpytest(p, "-vv")
 | 
					        result = pytester.runpytest(p, "-vv")
 | 
				
			||||||
        result.assert_outcomes(failed=0, passed=1)
 | 
					        result.assert_outcomes(failed=0, passed=1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
					    @pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
 | 
				
			||||||
    def test_comparing_two_different_data_classes(self, testdir):
 | 
					    def test_comparing_two_different_data_classes(self, pytester: Pytester) -> None:
 | 
				
			||||||
        p = testdir.copy_example(
 | 
					        p = pytester.copy_example(
 | 
				
			||||||
            "dataclasses/test_compare_two_different_dataclasses.py"
 | 
					            "dataclasses/test_compare_two_different_dataclasses.py"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        result = testdir.runpytest(p, "-vv")
 | 
					        result = pytester.runpytest(p, "-vv")
 | 
				
			||||||
        result.assert_outcomes(failed=0, passed=1)
 | 
					        result.assert_outcomes(failed=0, passed=1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -939,7 +951,7 @@ class TestAssert_reprcompare_attrsclass:
 | 
				
			||||||
        assert "Omitting" not in lines[2]
 | 
					        assert "Omitting" not in lines[2]
 | 
				
			||||||
        assert lines[3] == "['field_a']"
 | 
					        assert lines[3] == "['field_a']"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_attrs_with_attribute_comparison_off(self):
 | 
					    def test_attrs_with_attribute_comparison_off(self) -> None:
 | 
				
			||||||
        @attr.s
 | 
					        @attr.s
 | 
				
			||||||
        class SimpleDataObject:
 | 
					        class SimpleDataObject:
 | 
				
			||||||
            field_a = attr.ib()
 | 
					            field_a = attr.ib()
 | 
				
			||||||
| 
						 | 
					@ -957,7 +969,7 @@ class TestAssert_reprcompare_attrsclass:
 | 
				
			||||||
        for line in lines[3:]:
 | 
					        for line in lines[3:]:
 | 
				
			||||||
            assert "field_b" not in line
 | 
					            assert "field_b" not in line
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_comparing_two_different_attrs_classes(self):
 | 
					    def test_comparing_two_different_attrs_classes(self) -> None:
 | 
				
			||||||
        @attr.s
 | 
					        @attr.s
 | 
				
			||||||
        class SimpleDataObjectOne:
 | 
					        class SimpleDataObjectOne:
 | 
				
			||||||
            field_a = attr.ib()
 | 
					            field_a = attr.ib()
 | 
				
			||||||
| 
						 | 
					@ -976,48 +988,48 @@ class TestAssert_reprcompare_attrsclass:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestFormatExplanation:
 | 
					class TestFormatExplanation:
 | 
				
			||||||
    def test_special_chars_full(self, testdir):
 | 
					    def test_special_chars_full(self, pytester: Pytester) -> None:
 | 
				
			||||||
        # Issue 453, for the bug this would raise IndexError
 | 
					        # Issue 453, for the bug this would raise IndexError
 | 
				
			||||||
        testdir.makepyfile(
 | 
					        pytester.makepyfile(
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            def test_foo():
 | 
					            def test_foo():
 | 
				
			||||||
                assert '\\n}' == ''
 | 
					                assert '\\n}' == ''
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        result = testdir.runpytest()
 | 
					        result = pytester.runpytest()
 | 
				
			||||||
        assert result.ret == 1
 | 
					        assert result.ret == 1
 | 
				
			||||||
        result.stdout.fnmatch_lines(["*AssertionError*"])
 | 
					        result.stdout.fnmatch_lines(["*AssertionError*"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_simple(self):
 | 
					    def test_fmt_simple(self) -> None:
 | 
				
			||||||
        expl = "assert foo"
 | 
					        expl = "assert foo"
 | 
				
			||||||
        assert util.format_explanation(expl) == "assert foo"
 | 
					        assert util.format_explanation(expl) == "assert foo"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_where(self):
 | 
					    def test_fmt_where(self) -> None:
 | 
				
			||||||
        expl = "\n".join(["assert 1", "{1 = foo", "} == 2"])
 | 
					        expl = "\n".join(["assert 1", "{1 = foo", "} == 2"])
 | 
				
			||||||
        res = "\n".join(["assert 1 == 2", " +  where 1 = foo"])
 | 
					        res = "\n".join(["assert 1 == 2", " +  where 1 = foo"])
 | 
				
			||||||
        assert util.format_explanation(expl) == res
 | 
					        assert util.format_explanation(expl) == res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_and(self):
 | 
					    def test_fmt_and(self) -> None:
 | 
				
			||||||
        expl = "\n".join(["assert 1", "{1 = foo", "} == 2", "{2 = bar", "}"])
 | 
					        expl = "\n".join(["assert 1", "{1 = foo", "} == 2", "{2 = bar", "}"])
 | 
				
			||||||
        res = "\n".join(["assert 1 == 2", " +  where 1 = foo", " +  and   2 = bar"])
 | 
					        res = "\n".join(["assert 1 == 2", " +  where 1 = foo", " +  and   2 = bar"])
 | 
				
			||||||
        assert util.format_explanation(expl) == res
 | 
					        assert util.format_explanation(expl) == res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_where_nested(self):
 | 
					    def test_fmt_where_nested(self) -> None:
 | 
				
			||||||
        expl = "\n".join(["assert 1", "{1 = foo", "{foo = bar", "}", "} == 2"])
 | 
					        expl = "\n".join(["assert 1", "{1 = foo", "{foo = bar", "}", "} == 2"])
 | 
				
			||||||
        res = "\n".join(["assert 1 == 2", " +  where 1 = foo", " +    where foo = bar"])
 | 
					        res = "\n".join(["assert 1 == 2", " +  where 1 = foo", " +    where foo = bar"])
 | 
				
			||||||
        assert util.format_explanation(expl) == res
 | 
					        assert util.format_explanation(expl) == res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_newline(self):
 | 
					    def test_fmt_newline(self) -> None:
 | 
				
			||||||
        expl = "\n".join(['assert "foo" == "bar"', "~- foo", "~+ bar"])
 | 
					        expl = "\n".join(['assert "foo" == "bar"', "~- foo", "~+ bar"])
 | 
				
			||||||
        res = "\n".join(['assert "foo" == "bar"', "  - foo", "  + bar"])
 | 
					        res = "\n".join(['assert "foo" == "bar"', "  - foo", "  + bar"])
 | 
				
			||||||
        assert util.format_explanation(expl) == res
 | 
					        assert util.format_explanation(expl) == res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_newline_escaped(self):
 | 
					    def test_fmt_newline_escaped(self) -> None:
 | 
				
			||||||
        expl = "\n".join(["assert foo == bar", "baz"])
 | 
					        expl = "\n".join(["assert foo == bar", "baz"])
 | 
				
			||||||
        res = "assert foo == bar\\nbaz"
 | 
					        res = "assert foo == bar\\nbaz"
 | 
				
			||||||
        assert util.format_explanation(expl) == res
 | 
					        assert util.format_explanation(expl) == res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_newline_before_where(self):
 | 
					    def test_fmt_newline_before_where(self) -> None:
 | 
				
			||||||
        expl = "\n".join(
 | 
					        expl = "\n".join(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
                "the assertion message here",
 | 
					                "the assertion message here",
 | 
				
			||||||
| 
						 | 
					@ -1038,7 +1050,7 @@ class TestFormatExplanation:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        assert util.format_explanation(expl) == res
 | 
					        assert util.format_explanation(expl) == res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_fmt_multi_newline_before_where(self):
 | 
					    def test_fmt_multi_newline_before_where(self) -> None:
 | 
				
			||||||
        expl = "\n".join(
 | 
					        expl = "\n".join(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
                "the assertion",
 | 
					                "the assertion",
 | 
				
			||||||
| 
						 | 
					@ -1072,12 +1084,12 @@ class TestTruncateExplanation:
 | 
				
			||||||
        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
 | 
					        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
 | 
				
			||||||
        assert result == expl
 | 
					        assert result == expl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_doesnt_truncate_at_when_input_is_5_lines_and_LT_max_chars(self):
 | 
					    def test_doesnt_truncate_at_when_input_is_5_lines_and_LT_max_chars(self) -> None:
 | 
				
			||||||
        expl = ["a" * 100 for x in range(5)]
 | 
					        expl = ["a" * 100 for x in range(5)]
 | 
				
			||||||
        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80)
 | 
					        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80)
 | 
				
			||||||
        assert result == expl
 | 
					        assert result == expl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_truncates_at_8_lines_when_given_list_of_empty_strings(self):
 | 
					    def test_truncates_at_8_lines_when_given_list_of_empty_strings(self) -> None:
 | 
				
			||||||
        expl = ["" for x in range(50)]
 | 
					        expl = ["" for x in range(50)]
 | 
				
			||||||
        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
 | 
					        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
 | 
				
			||||||
        assert result != expl
 | 
					        assert result != expl
 | 
				
			||||||
| 
						 | 
					@ -1087,7 +1099,7 @@ class TestTruncateExplanation:
 | 
				
			||||||
        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
					        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
				
			||||||
        assert last_line_before_trunc_msg.endswith("...")
 | 
					        assert last_line_before_trunc_msg.endswith("...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_truncates_at_8_lines_when_first_8_lines_are_LT_max_chars(self):
 | 
					    def test_truncates_at_8_lines_when_first_8_lines_are_LT_max_chars(self) -> None:
 | 
				
			||||||
        expl = ["a" for x in range(100)]
 | 
					        expl = ["a" for x in range(100)]
 | 
				
			||||||
        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80)
 | 
					        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80)
 | 
				
			||||||
        assert result != expl
 | 
					        assert result != expl
 | 
				
			||||||
| 
						 | 
					@ -1097,7 +1109,7 @@ class TestTruncateExplanation:
 | 
				
			||||||
        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
					        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
				
			||||||
        assert last_line_before_trunc_msg.endswith("...")
 | 
					        assert last_line_before_trunc_msg.endswith("...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_truncates_at_8_lines_when_first_8_lines_are_EQ_max_chars(self):
 | 
					    def test_truncates_at_8_lines_when_first_8_lines_are_EQ_max_chars(self) -> None:
 | 
				
			||||||
        expl = ["a" * 80 for x in range(16)]
 | 
					        expl = ["a" * 80 for x in range(16)]
 | 
				
			||||||
        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80)
 | 
					        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80)
 | 
				
			||||||
        assert result != expl
 | 
					        assert result != expl
 | 
				
			||||||
| 
						 | 
					@ -1107,7 +1119,7 @@ class TestTruncateExplanation:
 | 
				
			||||||
        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
					        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
				
			||||||
        assert last_line_before_trunc_msg.endswith("...")
 | 
					        assert last_line_before_trunc_msg.endswith("...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_truncates_at_4_lines_when_first_4_lines_are_GT_max_chars(self):
 | 
					    def test_truncates_at_4_lines_when_first_4_lines_are_GT_max_chars(self) -> None:
 | 
				
			||||||
        expl = ["a" * 250 for x in range(10)]
 | 
					        expl = ["a" * 250 for x in range(10)]
 | 
				
			||||||
        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=999)
 | 
					        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=999)
 | 
				
			||||||
        assert result != expl
 | 
					        assert result != expl
 | 
				
			||||||
| 
						 | 
					@ -1117,7 +1129,7 @@ class TestTruncateExplanation:
 | 
				
			||||||
        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
					        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
				
			||||||
        assert last_line_before_trunc_msg.endswith("...")
 | 
					        assert last_line_before_trunc_msg.endswith("...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_truncates_at_1_line_when_first_line_is_GT_max_chars(self):
 | 
					    def test_truncates_at_1_line_when_first_line_is_GT_max_chars(self) -> None:
 | 
				
			||||||
        expl = ["a" * 250 for x in range(1000)]
 | 
					        expl = ["a" * 250 for x in range(1000)]
 | 
				
			||||||
        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
 | 
					        result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
 | 
				
			||||||
        assert result != expl
 | 
					        assert result != expl
 | 
				
			||||||
| 
						 | 
					@ -1127,13 +1139,13 @@ class TestTruncateExplanation:
 | 
				
			||||||
        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
					        last_line_before_trunc_msg = result[-self.LINES_IN_TRUNCATION_MSG - 1]
 | 
				
			||||||
        assert last_line_before_trunc_msg.endswith("...")
 | 
					        assert last_line_before_trunc_msg.endswith("...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_full_output_truncated(self, monkeypatch, testdir):
 | 
					    def test_full_output_truncated(self, monkeypatch, pytester: Pytester) -> None:
 | 
				
			||||||
        """Test against full runpytest() output."""
 | 
					        """Test against full runpytest() output."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        line_count = 7
 | 
					        line_count = 7
 | 
				
			||||||
        line_len = 100
 | 
					        line_len = 100
 | 
				
			||||||
        expected_truncated_lines = 2
 | 
					        expected_truncated_lines = 2
 | 
				
			||||||
        testdir.makepyfile(
 | 
					        pytester.makepyfile(
 | 
				
			||||||
            r"""
 | 
					            r"""
 | 
				
			||||||
            def test_many_lines():
 | 
					            def test_many_lines():
 | 
				
			||||||
                a = list([str(i)[0] * %d for i in range(%d)])
 | 
					                a = list([str(i)[0] * %d for i in range(%d)])
 | 
				
			||||||
| 
						 | 
					@ -1146,7 +1158,7 @@ class TestTruncateExplanation:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        monkeypatch.delenv("CI", raising=False)
 | 
					        monkeypatch.delenv("CI", raising=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        result = testdir.runpytest()
 | 
					        result = pytester.runpytest()
 | 
				
			||||||
        # without -vv, truncate the message showing a few diff lines only
 | 
					        # without -vv, truncate the message showing a few diff lines only
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
| 
						 | 
					@ -1157,23 +1169,23 @@ class TestTruncateExplanation:
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        result = testdir.runpytest("-vv")
 | 
					        result = pytester.runpytest("-vv")
 | 
				
			||||||
        result.stdout.fnmatch_lines(["* 6*"])
 | 
					        result.stdout.fnmatch_lines(["* 6*"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        monkeypatch.setenv("CI", "1")
 | 
					        monkeypatch.setenv("CI", "1")
 | 
				
			||||||
        result = testdir.runpytest()
 | 
					        result = pytester.runpytest()
 | 
				
			||||||
        result.stdout.fnmatch_lines(["* 6*"])
 | 
					        result.stdout.fnmatch_lines(["* 6*"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_python25_compile_issue257(testdir):
 | 
					def test_python25_compile_issue257(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_rewritten():
 | 
					        def test_rewritten():
 | 
				
			||||||
            assert 1 == 2
 | 
					            assert 1 == 2
 | 
				
			||||||
        # some comment
 | 
					        # some comment
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    assert result.ret == 1
 | 
					    assert result.ret == 1
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
| 
						 | 
					@ -1183,14 +1195,14 @@ def test_python25_compile_issue257(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_rewritten(testdir):
 | 
					def test_rewritten(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_rewritten():
 | 
					        def test_rewritten():
 | 
				
			||||||
            assert "@py_builtins" in globals()
 | 
					            assert "@py_builtins" in globals()
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    assert testdir.runpytest().ret == 0
 | 
					    assert pytester.runpytest().ret == 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_reprcompare_notin() -> None:
 | 
					def test_reprcompare_notin() -> None:
 | 
				
			||||||
| 
						 | 
					@ -1202,7 +1214,7 @@ def test_reprcompare_notin() -> None:
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_reprcompare_whitespaces():
 | 
					def test_reprcompare_whitespaces() -> None:
 | 
				
			||||||
    assert callequal("\r\n", "\n") == [
 | 
					    assert callequal("\r\n", "\n") == [
 | 
				
			||||||
        r"'\r\n' == '\n'",
 | 
					        r"'\r\n' == '\n'",
 | 
				
			||||||
        r"Strings contain only whitespace, escaping them using repr()",
 | 
					        r"Strings contain only whitespace, escaping them using repr()",
 | 
				
			||||||
| 
						 | 
					@ -1212,8 +1224,8 @@ def test_reprcompare_whitespaces():
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_pytest_assertrepr_compare_integration(testdir):
 | 
					def test_pytest_assertrepr_compare_integration(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_hello():
 | 
					        def test_hello():
 | 
				
			||||||
            x = set(range(100))
 | 
					            x = set(range(100))
 | 
				
			||||||
| 
						 | 
					@ -1222,7 +1234,7 @@ def test_pytest_assertrepr_compare_integration(testdir):
 | 
				
			||||||
            assert x == y
 | 
					            assert x == y
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            "*def test_hello():*",
 | 
					            "*def test_hello():*",
 | 
				
			||||||
| 
						 | 
					@ -1234,8 +1246,8 @@ def test_pytest_assertrepr_compare_integration(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_sequence_comparison_uses_repr(testdir):
 | 
					def test_sequence_comparison_uses_repr(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_hello():
 | 
					        def test_hello():
 | 
				
			||||||
            x = set("hello x")
 | 
					            x = set("hello x")
 | 
				
			||||||
| 
						 | 
					@ -1243,7 +1255,7 @@ def test_sequence_comparison_uses_repr(testdir):
 | 
				
			||||||
            assert x == y
 | 
					            assert x == y
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            "*def test_hello():*",
 | 
					            "*def test_hello():*",
 | 
				
			||||||
| 
						 | 
					@ -1256,19 +1268,20 @@ def test_sequence_comparison_uses_repr(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_assertrepr_loaded_per_dir(testdir):
 | 
					def test_assertrepr_loaded_per_dir(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(test_base=["def test_base(): assert 1 == 2"])
 | 
					    pytester.makepyfile(test_base=["def test_base(): assert 1 == 2"])
 | 
				
			||||||
    a = testdir.mkdir("a")
 | 
					    a = pytester.mkdir("a")
 | 
				
			||||||
    a_test = a.join("test_a.py")
 | 
					    a.joinpath("test_a.py").write_text("def test_a(): assert 1 == 2")
 | 
				
			||||||
    a_test.write("def test_a(): assert 1 == 2")
 | 
					    a.joinpath("conftest.py").write_text(
 | 
				
			||||||
    a_conftest = a.join("conftest.py")
 | 
					        'def pytest_assertrepr_compare(): return ["summary a"]'
 | 
				
			||||||
    a_conftest.write('def pytest_assertrepr_compare(): return ["summary a"]')
 | 
					    )
 | 
				
			||||||
    b = testdir.mkdir("b")
 | 
					    b = pytester.mkdir("b")
 | 
				
			||||||
    b_test = b.join("test_b.py")
 | 
					    b.joinpath("test_b.py").write_text("def test_b(): assert 1 == 2")
 | 
				
			||||||
    b_test.write("def test_b(): assert 1 == 2")
 | 
					    b.joinpath("conftest.py").write_text(
 | 
				
			||||||
    b_conftest = b.join("conftest.py")
 | 
					        'def pytest_assertrepr_compare(): return ["summary b"]'
 | 
				
			||||||
    b_conftest.write('def pytest_assertrepr_compare(): return ["summary b"]')
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					
 | 
				
			||||||
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            "*def test_base():*",
 | 
					            "*def test_base():*",
 | 
				
			||||||
| 
						 | 
					@ -1281,34 +1294,34 @@ def test_assertrepr_loaded_per_dir(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_assertion_options(testdir):
 | 
					def test_assertion_options(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_hello():
 | 
					        def test_hello():
 | 
				
			||||||
            x = 3
 | 
					            x = 3
 | 
				
			||||||
            assert x == 4
 | 
					            assert x == 4
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    assert "3 == 4" in result.stdout.str()
 | 
					    assert "3 == 4" in result.stdout.str()
 | 
				
			||||||
    result = testdir.runpytest_subprocess("--assert=plain")
 | 
					    result = pytester.runpytest_subprocess("--assert=plain")
 | 
				
			||||||
    result.stdout.no_fnmatch_line("*3 == 4*")
 | 
					    result.stdout.no_fnmatch_line("*3 == 4*")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_triple_quoted_string_issue113(testdir):
 | 
					def test_triple_quoted_string_issue113(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_hello():
 | 
					        def test_hello():
 | 
				
			||||||
            assert "" == '''
 | 
					            assert "" == '''
 | 
				
			||||||
    '''"""
 | 
					    '''"""
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest("--fulltrace")
 | 
					    result = pytester.runpytest("--fulltrace")
 | 
				
			||||||
    result.stdout.fnmatch_lines(["*1 failed*"])
 | 
					    result.stdout.fnmatch_lines(["*1 failed*"])
 | 
				
			||||||
    result.stdout.no_fnmatch_line("*SyntaxError*")
 | 
					    result.stdout.no_fnmatch_line("*SyntaxError*")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_traceback_failure(testdir):
 | 
					def test_traceback_failure(pytester: Pytester) -> None:
 | 
				
			||||||
    p1 = testdir.makepyfile(
 | 
					    p1 = pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def g():
 | 
					        def g():
 | 
				
			||||||
            return 2
 | 
					            return 2
 | 
				
			||||||
| 
						 | 
					@ -1318,7 +1331,7 @@ def test_traceback_failure(testdir):
 | 
				
			||||||
            f(3)
 | 
					            f(3)
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest(p1, "--tb=long")
 | 
					    result = pytester.runpytest(p1, "--tb=long")
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            "*test_traceback_failure.py F*",
 | 
					            "*test_traceback_failure.py F*",
 | 
				
			||||||
| 
						 | 
					@ -1340,7 +1353,7 @@ def test_traceback_failure(testdir):
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    result = testdir.runpytest(p1)  # "auto"
 | 
					    result = pytester.runpytest(p1)  # "auto"
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            "*test_traceback_failure.py F*",
 | 
					            "*test_traceback_failure.py F*",
 | 
				
			||||||
| 
						 | 
					@ -1362,9 +1375,9 @@ def test_traceback_failure(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_exception_handling_no_traceback(testdir):
 | 
					def test_exception_handling_no_traceback(pytester: Pytester) -> None:
 | 
				
			||||||
    """Handle chain exceptions in tasks submitted by the multiprocess module (#1984)."""
 | 
					    """Handle chain exceptions in tasks submitted by the multiprocess module (#1984)."""
 | 
				
			||||||
    p1 = testdir.makepyfile(
 | 
					    p1 = pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        from multiprocessing import Pool
 | 
					        from multiprocessing import Pool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1380,8 +1393,8 @@ def test_exception_handling_no_traceback(testdir):
 | 
				
			||||||
            multitask_job()
 | 
					            multitask_job()
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    testdir.syspathinsert()
 | 
					    pytester.syspathinsert()
 | 
				
			||||||
    result = testdir.runpytest(p1, "--tb=long")
 | 
					    result = pytester.runpytest(p1, "--tb=long")
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            "====* FAILURES *====",
 | 
					            "====* FAILURES *====",
 | 
				
			||||||
| 
						 | 
					@ -1419,27 +1432,27 @@ def test_exception_handling_no_traceback(testdir):
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
def test_warn_missing(testdir, cmdline_args, warning_output):
 | 
					def test_warn_missing(pytester: Pytester, cmdline_args, warning_output) -> None:
 | 
				
			||||||
    testdir.makepyfile("")
 | 
					    pytester.makepyfile("")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    result = testdir.run(sys.executable, *cmdline_args)
 | 
					    result = pytester.run(sys.executable, *cmdline_args)
 | 
				
			||||||
    result.stdout.fnmatch_lines(warning_output)
 | 
					    result.stdout.fnmatch_lines(warning_output)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_recursion_source_decode(testdir):
 | 
					def test_recursion_source_decode(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_something():
 | 
					        def test_something():
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    testdir.makeini(
 | 
					    pytester.makeini(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        [pytest]
 | 
					        [pytest]
 | 
				
			||||||
        python_files = *.py
 | 
					        python_files = *.py
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest("--collect-only")
 | 
					    result = pytester.runpytest("--collect-only")
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        <Module*>
 | 
					        <Module*>
 | 
				
			||||||
| 
						 | 
					@ -1447,15 +1460,15 @@ def test_recursion_source_decode(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_AssertionError_message(testdir):
 | 
					def test_AssertionError_message(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_hello():
 | 
					        def test_hello():
 | 
				
			||||||
            x,y = 1,2
 | 
					            x,y = 1,2
 | 
				
			||||||
            assert 0, (x,y)
 | 
					            assert 0, (x,y)
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        *def test_hello*
 | 
					        *def test_hello*
 | 
				
			||||||
| 
						 | 
					@ -1465,15 +1478,15 @@ def test_AssertionError_message(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_diff_newline_at_end(testdir):
 | 
					def test_diff_newline_at_end(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        r"""
 | 
					        r"""
 | 
				
			||||||
        def test_diff():
 | 
					        def test_diff():
 | 
				
			||||||
            assert 'asdf' == 'asdf\n'
 | 
					            assert 'asdf' == 'asdf\n'
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        r"""
 | 
					        r"""
 | 
				
			||||||
        *assert 'asdf' == 'asdf\n'
 | 
					        *assert 'asdf' == 'asdf\n'
 | 
				
			||||||
| 
						 | 
					@ -1485,67 +1498,67 @@ def test_diff_newline_at_end(testdir):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.filterwarnings("default")
 | 
					@pytest.mark.filterwarnings("default")
 | 
				
			||||||
def test_assert_tuple_warning(testdir):
 | 
					def test_assert_tuple_warning(pytester: Pytester) -> None:
 | 
				
			||||||
    msg = "assertion is always true"
 | 
					    msg = "assertion is always true"
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_tuple():
 | 
					        def test_tuple():
 | 
				
			||||||
            assert(False, 'you shall not pass')
 | 
					            assert(False, 'you shall not pass')
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines([f"*test_assert_tuple_warning.py:2:*{msg}*"])
 | 
					    result.stdout.fnmatch_lines([f"*test_assert_tuple_warning.py:2:*{msg}*"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # tuples with size != 2 should not trigger the warning
 | 
					    # tuples with size != 2 should not trigger the warning
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_tuple():
 | 
					        def test_tuple():
 | 
				
			||||||
            assert ()
 | 
					            assert ()
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    assert msg not in result.stdout.str()
 | 
					    assert msg not in result.stdout.str()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_assert_indirect_tuple_no_warning(testdir):
 | 
					def test_assert_indirect_tuple_no_warning(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test_tuple():
 | 
					        def test_tuple():
 | 
				
			||||||
            tpl = ('foo', 'bar')
 | 
					            tpl = ('foo', 'bar')
 | 
				
			||||||
            assert tpl
 | 
					            assert tpl
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    output = "\n".join(result.stdout.lines)
 | 
					    output = "\n".join(result.stdout.lines)
 | 
				
			||||||
    assert "WR1" not in output
 | 
					    assert "WR1" not in output
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_assert_with_unicode(testdir):
 | 
					def test_assert_with_unicode(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """\
 | 
					        """\
 | 
				
			||||||
        def test_unicode():
 | 
					        def test_unicode():
 | 
				
			||||||
            assert '유니코드' == 'Unicode'
 | 
					            assert '유니코드' == 'Unicode'
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(["*AssertionError*"])
 | 
					    result.stdout.fnmatch_lines(["*AssertionError*"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_raise_unprintable_assertion_error(testdir):
 | 
					def test_raise_unprintable_assertion_error(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        r"""
 | 
					        r"""
 | 
				
			||||||
        def test_raise_assertion_error():
 | 
					        def test_raise_assertion_error():
 | 
				
			||||||
            raise AssertionError('\xff')
 | 
					            raise AssertionError('\xff')
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [r">       raise AssertionError('\xff')", "E       AssertionError: *"]
 | 
					        [r">       raise AssertionError('\xff')", "E       AssertionError: *"]
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_raise_assertion_error_raisin_repr(testdir):
 | 
					def test_raise_assertion_error_raisin_repr(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        class RaisingRepr(object):
 | 
					        class RaisingRepr(object):
 | 
				
			||||||
            def __repr__(self):
 | 
					            def __repr__(self):
 | 
				
			||||||
| 
						 | 
					@ -1554,14 +1567,14 @@ def test_raise_assertion_error_raisin_repr(testdir):
 | 
				
			||||||
            raise AssertionError(RaisingRepr())
 | 
					            raise AssertionError(RaisingRepr())
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        ["E       AssertionError: <unprintable AssertionError object>"]
 | 
					        ["E       AssertionError: <unprintable AssertionError object>"]
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_issue_1944(testdir):
 | 
					def test_issue_1944(pytester: Pytester) -> None:
 | 
				
			||||||
    testdir.makepyfile(
 | 
					    pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def f():
 | 
					        def f():
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
| 
						 | 
					@ -1569,7 +1582,7 @@ def test_issue_1944(testdir):
 | 
				
			||||||
        assert f() == 10
 | 
					        assert f() == 10
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = pytester.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(["*1 error*"])
 | 
					    result.stdout.fnmatch_lines(["*1 error*"])
 | 
				
			||||||
    assert (
 | 
					    assert (
 | 
				
			||||||
        "AttributeError: 'Module' object has no attribute '_obj'"
 | 
					        "AttributeError: 'Module' object has no attribute '_obj'"
 | 
				
			||||||
| 
						 | 
					@ -1577,7 +1590,7 @@ def test_issue_1944(testdir):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_exit_from_assertrepr_compare(monkeypatch):
 | 
					def test_exit_from_assertrepr_compare(monkeypatch) -> None:
 | 
				
			||||||
    def raise_exit(obj):
 | 
					    def raise_exit(obj):
 | 
				
			||||||
        outcomes.exit("Quitting debugger")
 | 
					        outcomes.exit("Quitting debugger")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1587,16 +1600,16 @@ def test_exit_from_assertrepr_compare(monkeypatch):
 | 
				
			||||||
        callequal(1, 1)
 | 
					        callequal(1, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_assertion_location_with_coverage(testdir):
 | 
					def test_assertion_location_with_coverage(pytester: Pytester) -> None:
 | 
				
			||||||
    """This used to report the wrong location when run with coverage (#5754)."""
 | 
					    """This used to report the wrong location when run with coverage (#5754)."""
 | 
				
			||||||
    p = testdir.makepyfile(
 | 
					    p = pytester.makepyfile(
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        def test():
 | 
					        def test():
 | 
				
			||||||
            assert False, 1
 | 
					            assert False, 1
 | 
				
			||||||
            assert False, 2
 | 
					            assert False, 2
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    result = testdir.runpytest(str(p))
 | 
					    result = pytester.runpytest(str(p))
 | 
				
			||||||
    result.stdout.fnmatch_lines(
 | 
					    result.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            ">       assert False, 1",
 | 
					            ">       assert False, 1",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue