From 821b6ef2a68feba3e36bd5f2710dd2fbfe33a170 Mon Sep 17 00:00:00 2001 From: Danilo Horta Date: Mon, 11 Feb 2019 23:20:17 +0000 Subject: [PATCH 01/17] Avoid pkg_resources import at the top-level. --- changelog/4768.trivial.rst | 1 + src/_pytest/config/__init__.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/4768.trivial.rst diff --git a/changelog/4768.trivial.rst b/changelog/4768.trivial.rst new file mode 100644 index 000000000..c84b29b79 --- /dev/null +++ b/changelog/4768.trivial.rst @@ -0,0 +1 @@ +Avoid pkg_resources import at the top-level. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 3943f8472..976f2366b 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -14,7 +14,6 @@ import warnings import py import six -from pkg_resources import parse_version from pluggy import HookimplMarker from pluggy import HookspecMarker from pluggy import PluginManager @@ -815,6 +814,7 @@ class Config(object): def _checkversion(self): import pytest + from pkg_resources import parse_version minver = self.inicfg.get("minversion", None) if minver: From a70c1ca1005c222cc0ee32b6bca9c112ec9c0457 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 4 Mar 2019 16:55:03 +0100 Subject: [PATCH 02/17] ci: Travis: disable cache by default, only for pre-commit For pip the usual http caching should be good enough. This keeps the cache for pre-commit with the linting env for now. Ref: https://github.com/pytest-dev/pytest/issues/3502 --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03b502c80..750f93f81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,6 +86,9 @@ jobs: - env: TOXENV=py36-xdist python: '3.6' - env: TOXENV=linting,docs,doctesting PYTEST_COVERAGE=1 + cache: + directories: + - $HOME/.cache/pre-commit - stage: deploy python: '3.6' @@ -144,7 +147,4 @@ notifications: skip_join: true email: - pytest-commit@python.org -cache: - directories: - - $HOME/.cache/pip - - $HOME/.cache/pre-commit +cache: false From 0f4905a25917ccffa3e7221d18e2c3ed2f6c9298 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 7 Mar 2019 08:08:21 -0300 Subject: [PATCH 03/17] Simplify 'obj' property definition in PyobjMixin This uses modern property definition syntax, declaring both getter and setter as obj() functions --- src/_pytest/python.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 215015d27..567d3ee67 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -243,25 +243,24 @@ class PyobjMixin(PyobjContext): def __init__(self, *k, **kw): super(PyobjMixin, self).__init__(*k, **kw) - def obj(): - def fget(self): - obj = getattr(self, "_obj", None) - if obj is None: - self._obj = obj = self._getobj() - # XXX evil hack - # used to avoid Instance collector marker duplication - if self._ALLOW_MARKERS: - self.own_markers.extend(get_unpacked_marks(self.obj)) - return obj + @property + def obj(self): + """underlying python object""" + obj = getattr(self, "_obj", None) + if obj is None: + self._obj = obj = self._getobj() + # XXX evil hack + # used to avoid Instance collector marker duplication + if self._ALLOW_MARKERS: + self.own_markers.extend(get_unpacked_marks(self.obj)) + return obj - def fset(self, value): - self._obj = value - - return property(fget, fset, None, "underlying python object") - - obj = obj() + @obj.setter + def obj(self, value): + self._obj = value def _getobj(self): + """Gets the underlying python object. May be overwritten by subclasses.""" return getattr(self.parent.obj, self.name) def getmodpath(self, stopatmodule=True, includemodule=False): From de5aa3847e032382447bdcf5ca8397d8a0be1208 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 7 Mar 2019 12:53:47 -0300 Subject: [PATCH 04/17] Apply suggestions from code review Co-Authored-By: nicoddemus --- src/_pytest/python.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 567d3ee67..07767f391 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -245,7 +245,7 @@ class PyobjMixin(PyobjContext): @property def obj(self): - """underlying python object""" + """Underlying Python object.""" obj = getattr(self, "_obj", None) if obj is None: self._obj = obj = self._getobj() @@ -260,7 +260,7 @@ class PyobjMixin(PyobjContext): self._obj = value def _getobj(self): - """Gets the underlying python object. May be overwritten by subclasses.""" + """Gets the underlying Python object. May be overwritten by subclasses.""" return getattr(self.parent.obj, self.name) def getmodpath(self, stopatmodule=True, includemodule=False): From 2d43f4276958cd3070fee8347ac543a4e259497f Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Fri, 8 Mar 2019 09:21:56 -0500 Subject: [PATCH 05/17] Add missing plugin hooks to docs pytest-dev/pytest#4896 --- doc/en/reference.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 7ab734075..ca1061a8f 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -584,6 +584,8 @@ Initialization hooks called for plugins and ``conftest.py`` files. .. autofunction:: pytest_sessionstart .. autofunction:: pytest_sessionfinish +.. autofunction:: pytest_plugin_registered + Test running hooks ~~~~~~~~~~~~~~~~~~ @@ -607,6 +609,8 @@ into interactive debugging when a test failure occurs. The :py:mod:`_pytest.terminal` reported specifically uses the reporting hook to print information about a test run. +.. autofunction:: pytest_pyfunc_call + Collection hooks ~~~~~~~~~~~~~~~~ @@ -616,6 +620,7 @@ Collection hooks .. autofunction:: pytest_ignore_collect .. autofunction:: pytest_collect_directory .. autofunction:: pytest_collect_file +.. autofunction:: pytest_pycollect_makemodule For influencing the collection of objects in Python modules you can use the following hook: @@ -629,12 +634,15 @@ items, delete or otherwise amend the test items: .. autofunction:: pytest_collection_modifyitems +.. autofunction:: pytest_collection_finish + Reporting hooks ~~~~~~~~~~~~~~~ Session related reporting hooks: .. autofunction:: pytest_collectstart +.. autofunction:: pytest_make_collect_report .. autofunction:: pytest_itemcollected .. autofunction:: pytest_collectreport .. autofunction:: pytest_deselected From dc7ae41f332153173866c02636758643559393e1 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Fri, 8 Mar 2019 09:22:00 -0800 Subject: [PATCH 06/17] Fix broken error message in pytester --- src/_pytest/pytester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index fae243a50..a959516b0 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -693,7 +693,7 @@ class Testdir(object): else: raise LookupError( "{} cant be found as module or package in {}".format( - func_name, example_dir.bestrelpath(self.request.confg.rootdir) + func_name, example_dir.bestrelpath(self.request.config.rootdir) ) ) else: From 877b57ae9b38b799311a6703986109670d0c624b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 8 Mar 2019 22:33:07 -0300 Subject: [PATCH 07/17] Add CHANGELOG entry --- changelog/4898.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/4898.trivial.rst diff --git a/changelog/4898.trivial.rst b/changelog/4898.trivial.rst new file mode 100644 index 000000000..43efee011 --- /dev/null +++ b/changelog/4898.trivial.rst @@ -0,0 +1 @@ +Fix ``AttributeError: FixtureRequest has no 'confg' attribute`` bug in ``testdir.copy_example``. From a0f652c5597bd01e560eb87283d18520b34ed080 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 8 Mar 2019 22:41:57 -0300 Subject: [PATCH 08/17] Rename 4898.trivial.rst to 4898.bugfix.rst --- changelog/{4898.trivial.rst => 4898.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog/{4898.trivial.rst => 4898.bugfix.rst} (100%) diff --git a/changelog/4898.trivial.rst b/changelog/4898.bugfix.rst similarity index 100% rename from changelog/4898.trivial.rst rename to changelog/4898.bugfix.rst From 489c61a22da0baa00d463f9780144befd68c2903 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Sun, 10 Mar 2019 05:03:24 +0100 Subject: [PATCH 09/17] Allow tests to pass after 2038 without this change, the python-apache-libcloud tests failed in the year 2039 with fp.write(struct.pack(" Date: Mon, 11 Mar 2019 12:59:54 -0300 Subject: [PATCH 10/17] Prepare release 4.3.1 --- CHANGELOG.rst | 22 ++++++++++++++++++++++ changelog/4768.trivial.rst | 1 - changelog/4810.bugfix.rst | 1 - changelog/4861.bugfix.rst | 1 - changelog/4898.bugfix.rst | 1 - doc/en/announce/index.rst | 1 + doc/en/announce/release-4.3.1.rst | 29 +++++++++++++++++++++++++++++ doc/en/example/parametrize.rst | 6 ++++-- doc/en/tmpdir.rst | 1 - 9 files changed, 56 insertions(+), 7 deletions(-) delete mode 100644 changelog/4768.trivial.rst delete mode 100644 changelog/4810.bugfix.rst delete mode 100644 changelog/4861.bugfix.rst delete mode 100644 changelog/4898.bugfix.rst create mode 100644 doc/en/announce/release-4.3.1.rst diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9f98f6408..839b4c439 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -18,6 +18,28 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 4.3.1 (2019-03-11) +========================= + +Bug Fixes +--------- + +- `#4810 `_: Logging messages inside ``pytest_runtest_logreport()`` are now properly captured and displayed. + + +- `#4861 `_: Improve validation of contents written to captured output so it behaves the same as when capture is disabled. + + +- `#4898 `_: Fix ``AttributeError: FixtureRequest has no 'confg' attribute`` bug in ``testdir.copy_example``. + + + +Trivial/Internal Changes +------------------------ + +- `#4768 `_: Avoid pkg_resources import at the top-level. + + pytest 4.3.0 (2019-02-16) ========================= diff --git a/changelog/4768.trivial.rst b/changelog/4768.trivial.rst deleted file mode 100644 index c84b29b79..000000000 --- a/changelog/4768.trivial.rst +++ /dev/null @@ -1 +0,0 @@ -Avoid pkg_resources import at the top-level. diff --git a/changelog/4810.bugfix.rst b/changelog/4810.bugfix.rst deleted file mode 100644 index 32d9b97a5..000000000 --- a/changelog/4810.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Logging messages inside ``pytest_runtest_logreport()`` are now properly captured and displayed. diff --git a/changelog/4861.bugfix.rst b/changelog/4861.bugfix.rst deleted file mode 100644 index b4bf125d1..000000000 --- a/changelog/4861.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Improve validation of contents written to captured output so it behaves the same as when capture is disabled. diff --git a/changelog/4898.bugfix.rst b/changelog/4898.bugfix.rst deleted file mode 100644 index 43efee011..000000000 --- a/changelog/4898.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix ``AttributeError: FixtureRequest has no 'confg' attribute`` bug in ``testdir.copy_example``. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index 9574229d0..96123f3fb 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-4.3.1 release-4.3.0 release-4.2.1 release-4.2.0 diff --git a/doc/en/announce/release-4.3.1.rst b/doc/en/announce/release-4.3.1.rst new file mode 100644 index 000000000..45d14fffe --- /dev/null +++ b/doc/en/announce/release-4.3.1.rst @@ -0,0 +1,29 @@ +pytest-4.3.1 +======================================= + +pytest 4.3.1 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: + +* Andras Mitzki +* Anthony Sottile +* Bruno Oliveira +* Daniel Hahler +* Danilo Horta +* Grygorii Iermolenko +* Jeff Hale +* Kyle Altendorf +* Stephan Hoyer +* Zac Hatfield-Dodds +* Zac-HD +* songbowen + + +Happy testing, +The pytest Development Team diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 05932d164..b5d4693ad 100644 --- a/doc/en/example/parametrize.rst +++ b/doc/en/example/parametrize.rst @@ -436,8 +436,10 @@ Running it results in some skips if we don't have all the python interpreters in .. code-block:: pytest . $ pytest -rs -q multipython.py - ........................... [100%] - 27 passed in 0.12 seconds + ...sss...sssssssss...sss... [100%] + ========================= short test summary info ========================== + SKIPPED [15] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.4' not found + 12 passed, 15 skipped in 0.12 seconds Indirect parametrization of optional implementations/imports -------------------------------------------------------------------- diff --git a/doc/en/tmpdir.rst b/doc/en/tmpdir.rst index e2b8fc32b..f16b9260c 100644 --- a/doc/en/tmpdir.rst +++ b/doc/en/tmpdir.rst @@ -66,7 +66,6 @@ Running this would result in a passed test except for the last test_tmp_path.py:13: AssertionError ========================= 1 failed in 0.12 seconds ========================= - .. _`tmp_path_factory example`: The ``tmp_path_factory`` fixture From d32ab6029feb178df664e0d347e234cc4480eb7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 12 Mar 2019 16:28:10 +0100 Subject: [PATCH 11/17] Fix pytest tests invocation with custom PYTHONPATH Fixes https://github.com/pytest-dev/pytest/issues/4913 Co-authored-by: Bruno Oliveira --- changelog/4913.trivial.rst | 1 + testing/test_collection.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelog/4913.trivial.rst diff --git a/changelog/4913.trivial.rst b/changelog/4913.trivial.rst new file mode 100644 index 000000000..7846775cc --- /dev/null +++ b/changelog/4913.trivial.rst @@ -0,0 +1 @@ +Fix pytest tests invocation with custom ``PYTHONPATH``. diff --git a/testing/test_collection.py b/testing/test_collection.py index 97c46d8c2..37f7ad89c 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -2,6 +2,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import os import pprint import sys import textwrap @@ -1108,7 +1109,7 @@ def test_collect_pyargs_with_testpaths(testdir, monkeypatch): """ ) ) - monkeypatch.setenv("PYTHONPATH", str(testdir.tmpdir)) + monkeypatch.setenv("PYTHONPATH", str(testdir.tmpdir), prepend=os.pathsep) with root.as_cwd(): result = testdir.runpytest_subprocess() result.stdout.fnmatch_lines(["*1 passed in*"]) From f4bcb44025889d7a37577a6c9de331f52b14f7c9 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 13 Mar 2019 02:36:15 +0100 Subject: [PATCH 12/17] docs: pin Sphinx to <2.0 Ref: https://github.com/pytest-dev/pytest/issues/4912 --- doc/en/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/requirements.txt b/doc/en/requirements.txt index 4e2b8ce1a..320ee8dcd 100644 --- a/doc/en/requirements.txt +++ b/doc/en/requirements.txt @@ -1,4 +1,4 @@ pygments-pytest>=1.1.0 -sphinx>=1.8.2 +sphinx>=1.8.2,<2.0 sphinxcontrib-trio sphinx-removed-in>=0.1.3 From 44cb51010c928948d7b6bff1713f1eb6c6f349a2 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 13 Mar 2019 18:52:30 -0300 Subject: [PATCH 13/17] Improve CHANGELOG and code comment --- changelog/4903.bugfix.rst | 2 +- src/_pytest/assertion/rewrite.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog/4903.bugfix.rst b/changelog/4903.bugfix.rst index 1e80fecbf..116e1b0fd 100644 --- a/changelog/4903.bugfix.rst +++ b/changelog/4903.bugfix.rst @@ -1 +1 @@ -Fix handling of mtime to work after year 2038 +Use the correct modified time for years after 2038 in rewritten ``.pyc`` files. diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 3b53fd395..04ecbce5f 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -344,8 +344,10 @@ def _write_pyc(state, co, source_stat, pyc): try: with atomicwrites.atomic_write(pyc, mode="wb", overwrite=True) as fp: fp.write(imp.get_magic()) + # as of now, bytecode header expects 32-bit numbers for size and mtime (#4903) mtime = int(source_stat.mtime) & 0xFFFFFFFF size = source_stat.size & 0xFFFFFFFF + # " Date: Thu, 14 Mar 2019 12:15:05 +0100 Subject: [PATCH 14/17] Remove deprecated Sphinx directive add_description_unit() Partial solution for https://github.com/pytest-dev/pytest/issues/4912 --- changelog/4912.trivial.rst | 1 + doc/en/conf.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/4912.trivial.rst diff --git a/changelog/4912.trivial.rst b/changelog/4912.trivial.rst new file mode 100644 index 000000000..9c5ca6d8e --- /dev/null +++ b/changelog/4912.trivial.rst @@ -0,0 +1 @@ +Remove deprecated Sphinx directive, ``add_description_unit()``. diff --git a/doc/en/conf.py b/doc/en/conf.py index 74a43596e..5daa15a06 100644 --- a/doc/en/conf.py +++ b/doc/en/conf.py @@ -335,7 +335,7 @@ intersphinx_mapping = {"python": ("https://docs.python.org/3", None)} def setup(app): # from sphinx.ext.autodoc import cut_lines # app.connect('autodoc-process-docstring', cut_lines(4, what=['module'])) - app.add_description_unit( + app.add_object_type( "confval", "confval", objname="configuration value", From bd70f5c1488a7a74900670e3dad2cc2e32744c8a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 14 Mar 2019 08:16:07 -0300 Subject: [PATCH 15/17] Add test for mtime issue in #4903 --- testing/test_assertrewrite.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 098e106f9..bdfbf823c 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -1197,6 +1197,29 @@ class TestIssue2121: result.stdout.fnmatch_lines("*E*assert (1 + 1) == 3") +@pytest.mark.parametrize("offset", [-1, +1]) +def test_source_mtime_long_long(testdir, offset): + """Support modification dates after 2038 in rewritten files (#4903). + + pytest would crash with: + + fp.write(struct.pack(" Date: Thu, 14 Mar 2019 18:32:42 +0100 Subject: [PATCH 16/17] tests: fix test_pdb_interaction_continue_recursive with pdbpp --- testing/test_pdb.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 43d640614..0b92aa356 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -528,15 +528,13 @@ class TestPDB(object): import sys import types - newglobals = { - 'Pdb': self.__class__, # NOTE: different with pdb.Pdb - 'sys': sys, - } if sys.version_info < (3, ): do_debug_func = pdb.Pdb.do_debug.im_func else: do_debug_func = pdb.Pdb.do_debug + newglobals = do_debug_func.__globals__.copy() + newglobals['Pdb'] = self.__class__ orig_do_debug = types.FunctionType( do_debug_func.__code__, newglobals, do_debug_func.__name__, do_debug_func.__defaults__, From bdac9d3dd0fc21cbfe63108c3180f7f90b8aea08 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 14 Mar 2019 19:06:46 +0100 Subject: [PATCH 17/17] tests: improve test_pdb_interaction_doctest - ignore pdbrc (might be done in general, but this was the only affected test) - fail faster in case of unexpected failure --- testing/test_pdb.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 0b92aa356..68cb1cf00 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -457,7 +457,7 @@ class TestPDB(object): child.read() self.flush(child) - def test_pdb_interaction_doctest(self, testdir): + def test_pdb_interaction_doctest(self, testdir, monkeypatch): p1 = testdir.makepyfile( """ import pytest @@ -468,11 +468,18 @@ class TestPDB(object): ''' """ ) + # Prevent ~/.pdbrc etc to output anything. + monkeypatch.setenv("HOME", str(testdir)) + child = testdir.spawn_pytest("--doctest-modules --pdb %s" % p1) child.expect("Pdb") - child.sendline("i") - child.expect("0") + + assert "UNEXPECTED EXCEPTION: AssertionError()" in child.before.decode("utf8") + + child.sendline("'i=%i.' % i") child.expect("Pdb") + assert "\r\n'i=0.'\r\n" in child.before.decode("utf8") + child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest