From b8787b8732f7528efeebab9caa18a12bf556dddb Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 22 Jan 2020 14:30:55 +0100 Subject: [PATCH 1/2] tests: fix test_cwd_snapshot Without restoring the cwd, successive tests might fail to parse the config (via `_pytest.config._prepareconfig()`, for when `--lsof` is used). And it is good practice to restore the cwd in any case anyway. --- src/_pytest/pytester.py | 2 ++ testing/test_pytester.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index c1aa34bcfac..8e7fa5e09bb 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -527,6 +527,8 @@ class Testdir: """ + __test__ = False + CLOSE_STDIN = object class TimeoutExpired(Exception): diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 6c8c933d7e9..869e35db3e1 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -16,6 +16,7 @@ from _pytest.pytester import LineMatcher from _pytest.pytester import SysModulesSnapshot from _pytest.pytester import SysPathsSnapshot +from _pytest.pytester import Testdir def test_make_hook_recorder(testdir) -> None: @@ -273,7 +274,8 @@ def test_assert_outcomes_after_pytest_error(testdir) -> None: result.assert_outcomes(passed=0) -def test_cwd_snapshot(tmpdir) -> None: +def test_cwd_snapshot(testdir: Testdir) -> None: + tmpdir = testdir.tmpdir foo = tmpdir.ensure("foo", dir=1) bar = tmpdir.ensure("bar", dir=1) foo.chdir() From d878d9d4d55c81f7bc5d5adf97b3af79191272dd Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 22 Jan 2020 15:36:35 +0100 Subject: [PATCH 2/2] tests: use NotImplementedError with uncovered code --- testing/test_runner.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/testing/test_runner.py b/testing/test_runner.py index ecb60d4bee2..1600b6b7ce0 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -557,7 +557,7 @@ def test_outcomeexception_passes_except_Exception() -> None: try: raise outcomes.OutcomeException("test") except Exception: - pass + raise NotImplementedError() def test_pytest_exit() -> None: @@ -740,8 +740,9 @@ def f(): mod2 = pytest.importorskip("hello123", minversion="1.3") assert mod2 == mod except Skipped: - print(_pytest._code.ExceptionInfo.from_current()) - pytest.fail("spurious skip") + raise NotImplementedError( + "spurious skip: {}".format(_pytest._code.ExceptionInfo.from_current()) + ) def test_importorskip_imports_last_module_part() -> None: @@ -759,8 +760,9 @@ def test_importorskip_dev_module(monkeypatch) -> None: with pytest.raises(Skipped): pytest.importorskip("mockmodule1", minversion="0.14.0") except Skipped: - print(_pytest._code.ExceptionInfo.from_current()) - pytest.fail("spurious skip") + raise NotImplementedError( + "spurious skip: {}".format(_pytest._code.ExceptionInfo.from_current()) + ) def test_importorskip_module_level(testdir) -> None: @@ -1030,7 +1032,7 @@ def test_outcome_exception_bad_msg() -> None: """Check that OutcomeExceptions validate their input to prevent confusing errors (#5578)""" def func() -> None: - pass + raise NotImplementedError() expected = ( "OutcomeException expected string as 'msg' parameter, got 'function' instead.\n"