From 64ee1ee81b634ea5a1d4dc1914a18347973ee882 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 9 Dec 2018 11:53:41 +0100 Subject: [PATCH 1/3] tests: fix tests that require PYTEST_DISABLE_PLUGIN_AUTOLOAD to be unset Fix pytest's own tests with PYTEST_DISABLE_PLUGIN_AUTOLOAD=1. --- testing/test_assertion.py | 3 ++- testing/test_config.py | 3 +++ testing/test_junitxml.py | 3 ++- testing/test_terminal.py | 12 ++++++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index b6c31aba2..6f5852e54 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -153,7 +153,8 @@ class TestImportHookInstallation(object): @pytest.mark.parametrize("mode", ["plain", "rewrite"]) @pytest.mark.parametrize("plugin_state", ["development", "installed"]) - def test_installed_plugin_rewrite(self, testdir, mode, plugin_state): + def test_installed_plugin_rewrite(self, testdir, mode, plugin_state, monkeypatch): + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) # Make sure the hook is installed early enough so that plugins # installed via setuptools are rewritten. testdir.tmpdir.join("hampkg").ensure(dir=1) diff --git a/testing/test_config.py b/testing/test_config.py index 605d28aa0..185c7d396 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -511,6 +511,7 @@ def test_options_on_small_file_do_not_blow_up(testdir): def test_preparse_ordering_with_setuptools(testdir, monkeypatch): pkg_resources = pytest.importorskip("pkg_resources") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) def my_iter(name): assert name == "pytest11" @@ -548,6 +549,7 @@ def test_preparse_ordering_with_setuptools(testdir, monkeypatch): def test_setuptools_importerror_issue1479(testdir, monkeypatch): pkg_resources = pytest.importorskip("pkg_resources") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) def my_iter(name): assert name == "pytest11" @@ -576,6 +578,7 @@ def test_setuptools_importerror_issue1479(testdir, monkeypatch): @pytest.mark.parametrize("block_it", [True, False]) def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch, block_it): pkg_resources = pytest.importorskip("pkg_resources") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) plugin_module_placeholder = object() diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index c9dc39f82..e04af1ec3 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -1032,12 +1032,13 @@ def test_record_attribute(testdir): ) -def test_random_report_log_xdist(testdir): +def test_random_report_log_xdist(testdir, monkeypatch): """xdist calls pytest_runtest_logreport as they are executed by the slaves, with nodes from several nodes overlapping, so junitxml must cope with that to produce correct reports. #1064 """ pytest.importorskip("xdist") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) testdir.makepyfile( """ import pytest, time diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 86ec1cd07..019dd66f4 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1331,13 +1331,15 @@ class TestProgressOutputStyle(object): ] ) - def test_xdist_normal(self, many_tests_files, testdir): + def test_xdist_normal(self, many_tests_files, testdir, monkeypatch): pytest.importorskip("xdist") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) output = testdir.runpytest("-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[100%\]"]) - def test_xdist_normal_count(self, many_tests_files, testdir): + def test_xdist_normal_count(self, many_tests_files, testdir, monkeypatch): pytest.importorskip("xdist") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) testdir.makeini( """ [pytest] @@ -1347,8 +1349,9 @@ class TestProgressOutputStyle(object): output = testdir.runpytest("-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[20/20\]"]) - def test_xdist_verbose(self, many_tests_files, testdir): + def test_xdist_verbose(self, many_tests_files, testdir, monkeypatch): pytest.importorskip("xdist") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) output = testdir.runpytest("-n2", "-v") output.stdout.re_match_lines_random( [ @@ -1442,7 +1445,8 @@ class TestProgressWithTeardown(object): ] ) - def test_xdist_normal(self, many_files, testdir): + def test_xdist_normal(self, many_files, testdir, monkeypatch): pytest.importorskip("xdist") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) output = testdir.runpytest("-n2") output.stdout.re_match_lines([r"[\.E]{40} \s+ \[100%\]"]) From a254ad0436a922cb180015cdaec1bfe1cef8eb07 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 12 Dec 2018 14:58:48 -0800 Subject: [PATCH 2/3] Raise `TypeError` for `with raises(..., match=)`. --- changelog/4538.bugfix.rst | 1 + src/_pytest/python_api.py | 2 +- testing/python/raises.py | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelog/4538.bugfix.rst diff --git a/changelog/4538.bugfix.rst b/changelog/4538.bugfix.rst new file mode 100644 index 000000000..0ecfb5be0 --- /dev/null +++ b/changelog/4538.bugfix.rst @@ -0,0 +1 @@ +Raise ``TypeError`` for ``with raises(..., match=)``. diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 7de8e154c..37eafa7f0 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -716,6 +716,6 @@ class RaisesContext(object): suppress_exception = issubclass(self.excinfo.type, self.expected_exception) if sys.version_info[0] == 2 and suppress_exception: sys.exc_clear() - if self.match_expr and suppress_exception: + if self.match_expr is not None and suppress_exception: self.excinfo.match(self.match_expr) return suppress_exception diff --git a/testing/python/raises.py b/testing/python/raises.py index 912d34673..2ee18b173 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -37,6 +37,11 @@ class TestRaises(object): except pytest.raises.Exception: pass + def test_raises_falsey_type_error(self): + with pytest.raises(TypeError): + with pytest.raises(AssertionError, match=0): + raise AssertionError("ohai") + def test_raises_repr_inflight(self): """Ensure repr() on an exception info inside a pytest.raises with block works (#4386)""" From 6c5a1150d46f0392e84d6c9f28ace48d5199ca22 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 13 Dec 2018 23:37:51 +0000 Subject: [PATCH 3/3] Preparing release version 4.0.2 --- CHANGELOG.rst | 25 +++++++++++++++++++++++++ changelog/1495.doc.rst | 1 - changelog/4265.bugfix.rst | 1 - changelog/4435.bugfix.rst | 1 - changelog/4500.bugfix.rst | 1 - changelog/4538.bugfix.rst | 1 - doc/en/announce/index.rst | 1 + doc/en/announce/release-4.0.2.rst | 24 ++++++++++++++++++++++++ doc/en/example/parametrize.rst | 2 +- 9 files changed, 51 insertions(+), 6 deletions(-) delete mode 100644 changelog/1495.doc.rst delete mode 100644 changelog/4265.bugfix.rst delete mode 100644 changelog/4435.bugfix.rst delete mode 100644 changelog/4500.bugfix.rst delete mode 100644 changelog/4538.bugfix.rst create mode 100644 doc/en/announce/release-4.0.2.rst diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8e0ba82e4..22f3ac862 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -18,6 +18,31 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 4.0.2 (2018-12-13) +========================= + +Bug Fixes +--------- + +- `#4265 `_: Validate arguments from the ``PYTEST_ADDOPTS`` environment variable and the ``addopts`` ini option separately. + + +- `#4435 `_: Fix ``raises(..., 'code(string)')`` frame filename. + + +- `#4500 `_: When a fixture yields and a log call is made after the test runs, and, if the test is interrupted, capture attributes are ``None``. + + +- `#4538 `_: Raise ``TypeError`` for ``with raises(..., match=)``. + + + +Improved Documentation +---------------------- + +- `#1495 `_: Document common doctest fixture directory tree structure pitfalls + + pytest 4.0.1 (2018-11-23) ========================= diff --git a/changelog/1495.doc.rst b/changelog/1495.doc.rst deleted file mode 100644 index ab7231333..000000000 --- a/changelog/1495.doc.rst +++ /dev/null @@ -1 +0,0 @@ -Document common doctest fixture directory tree structure pitfalls diff --git a/changelog/4265.bugfix.rst b/changelog/4265.bugfix.rst deleted file mode 100644 index 7b40737c3..000000000 --- a/changelog/4265.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Validate arguments from the ``PYTEST_ADDOPTS`` environment variable and the ``addopts`` ini option separately. diff --git a/changelog/4435.bugfix.rst b/changelog/4435.bugfix.rst deleted file mode 100644 index de60b5e62..000000000 --- a/changelog/4435.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix ``raises(..., 'code(string)')`` frame filename. diff --git a/changelog/4500.bugfix.rst b/changelog/4500.bugfix.rst deleted file mode 100644 index b84b6b117..000000000 --- a/changelog/4500.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -When a fixture yields and a log call is made after the test runs, and, if the test is interrupted, capture attributes are ``None``. diff --git a/changelog/4538.bugfix.rst b/changelog/4538.bugfix.rst deleted file mode 100644 index 0ecfb5be0..000000000 --- a/changelog/4538.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Raise ``TypeError`` for ``with raises(..., match=)``. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index 4120ccfc9..d6379f1b3 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-4.0.2 release-4.0.1 release-4.0.0 release-3.10.1 diff --git a/doc/en/announce/release-4.0.2.rst b/doc/en/announce/release-4.0.2.rst new file mode 100644 index 000000000..3b6e4be71 --- /dev/null +++ b/doc/en/announce/release-4.0.2.rst @@ -0,0 +1,24 @@ +pytest-4.0.2 +======================================= + +pytest 4.0.2 has just been released to PyPI. + +This is a bug-fix release, being a drop-in replacement. To upgrade:: + + pip install --upgrade pytest + +The full changelog is available at https://docs.pytest.org/en/latest/changelog.html. + +Thanks to all who contributed to this release, among them: + +* Anthony Sottile +* Bruno Oliveira +* Daniel Hahler +* Pedro Algarvio +* Ronny Pfannschmidt +* Tomer Keren +* Yash Todi + + +Happy testing, +The pytest Development Team diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 488f6e310..16e48878c 100644 --- a/doc/en/example/parametrize.rst +++ b/doc/en/example/parametrize.rst @@ -537,7 +537,7 @@ Then run ``pytest`` with verbose mode and with only the ``basic`` marker: $ pytest -v -m basic =========================== test session starts ============================ - platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python + platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6 cachedir: .pytest_cache rootdir: $REGENDOC_TMPDIR, inifile: collecting ... collected 17 items / 14 deselected