From 0f5fb7ed05c7911bbfe1583491f735c205453c34 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 29 Nov 2017 00:54:14 +0100 Subject: [PATCH 1/9] Fix ZeroDivisionError with 0 collected tests This can easily happen with pytest-testmon. --- _pytest/terminal.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 8538ee6aa..c5cbe14a1 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -313,8 +313,11 @@ class TerminalReporter: _PROGRESS_LENGTH = len(' [100%]') def _get_progress_information_message(self): - progress = self._progress_items_reported * 100 // self._session.testscollected - return ' [{:3d}%]'.format(progress) + collected = self._session.testscollected + if collected: + progress = self._progress_items_reported * 100 // collected + return ' [{:3d}%]'.format(progress) + return ' [100%]' def _write_progress_information_filling_space(self): if not self._show_progress_info: From 6bbd7410397fc3ea95b48cf38a3d8070ebf80fb7 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 28 Nov 2017 22:42:52 -0200 Subject: [PATCH 2/9] Add test for #2971 --- changelog/2971.bugfix | 1 + testing/test_terminal.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 changelog/2971.bugfix diff --git a/changelog/2971.bugfix b/changelog/2971.bugfix new file mode 100644 index 000000000..36684e8c8 --- /dev/null +++ b/changelog/2971.bugfix @@ -0,0 +1 @@ +Fix ``ZeroDivisionError`` when using the ``testmon`` plugin when no tests were actually collected. diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 98a8ca121..97c2f71fb 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -988,6 +988,24 @@ class TestProgress: """, ) + def test_zero_tests_collected(self, testdir): + """Some plugins (testmon for example) might issue pytest_runtest_logreport without any tests being + actually collected (#2971).""" + testdir.makeconftest(""" + def pytest_collection_modifyitems(items, config): + from _pytest.runner import CollectReport + for node_id in ('nodeid1', 'nodeid2'): + rep = CollectReport(node_id, 'passed', None, None) + rep.when = 'passed' + rep.duration = 0.1 + config.hook.pytest_runtest_logreport(report=rep) + """) + output = testdir.runpytest() + assert 'ZeroDivisionError' not in output.stdout.str() + output.stdout.fnmatch_lines([ + '=* 2 passed in *=', + ]) + def test_normal(self, many_tests_file, testdir): output = testdir.runpytest() output.stdout.re_match_lines([ From fdfc1946da9dff75747d734c26b3602edfec1226 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 29 Nov 2017 18:56:57 -0200 Subject: [PATCH 3/9] Add CHANGELOG entry about pytest.fixture "params" being now immutable Fix #2959 --- CHANGELOG.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2c3f5ff9c..7e7bfaf04 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -38,6 +38,14 @@ Deprecations and Removals with the boolean ``Node._skipped_by_mark``. (`#2767 `_) +- The ``params`` list passed to ``pytest.fixture`` is now for + all effects considered immutable and frozen at the moment of the ``pytest.fixture`` + call. Previously the list could be changed before the first invocation of the fixture + allowing for a form of dynamic parametrization (for example, updated from command-line options), + but this was an unwanted implementation detail which complicated the internals and prevented + some internal cleanup. See issue `#2959 `_ + for details and a recommended workaround. + Features -------- From 70f1e3b4b0cdcf428fdcf44b6bc62ad76e2a03b2 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Nov 2017 07:47:00 -0200 Subject: [PATCH 4/9] Improve getscopeitem assertion message Fix #2979 --- _pytest/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index 19b977224..e09ffaddb 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -553,7 +553,7 @@ class FixtureRequest(FuncargnamesCompatAttr): if node is None and scope == "class": # fallback to function item itself node = self._pyfuncitem - assert node + assert node, 'Could not obtain a node for scope "{}" for function {!r}'.format(scope, self._pyfuncitem) return node def __repr__(self): From cf0cac3b734dd47c8f6cbf3afa759231fbb76bc9 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Nov 2017 18:34:53 -0200 Subject: [PATCH 5/9] Bring back TerminalReporter.writer as an alias to TerminalReporter._tw Fix #2984 --- _pytest/terminal.py | 2 ++ changelog/2984.bugfix | 1 + testing/deprecated_test.py | 13 +++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 changelog/2984.bugfix diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 8538ee6aa..ca9b6e8e7 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -145,6 +145,8 @@ class TerminalReporter: if file is None: file = sys.stdout self._tw = _pytest.config.create_terminal_writer(config, file) + # self.writer will be deprecated in pytest-3.4 + self.writer = self._tw self._screen_width = self._tw.fullwidth self.currentfspath = None self.reportchars = getreportopt(config) diff --git a/changelog/2984.bugfix b/changelog/2984.bugfix new file mode 100644 index 000000000..21f5748d5 --- /dev/null +++ b/changelog/2984.bugfix @@ -0,0 +1 @@ +Bring back ``TerminalReporter.writer`` as an alias to ``TerminalReporter._tw``. This alias was removed by accident in the ``3.3.0`` release. diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index f3c40cb3d..11c4ad43c 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -101,6 +101,19 @@ def test_metafunc_addcall_deprecated(testdir): ]) +def test_terminal_reporter_writer_attr(pytestconfig): + """Check that TerminalReporter._tw is also available as 'writer' (#2984) + This attribute is planned to be deprecated in 3.4. + """ + try: + import xdist # noqa + pytest.skip('xdist workers disable the terminal reporter plugin') + except ImportError: + pass + terminal_reporter = pytestconfig.pluginmanager.get_plugin('terminalreporter') + assert terminal_reporter.writer is terminal_reporter._tw + + def test_pytest_catchlog_deprecated(testdir): testdir.makepyfile(""" def test_func(pytestconfig): From ce30896cd20953f4eca1f2acac904c3f7a8e0c78 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 5 Dec 2017 20:02:56 +0100 Subject: [PATCH 6/9] Also blacklist pytest-capturelog plugin This is the older plugin before pytest-catchlog was around. Apparently there are people still using it. Fixes #3004 --- _pytest/config.py | 7 ++++--- changelog/3004.bugfix | 1 + testing/deprecated_test.py | 9 +++++---- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 changelog/3004.bugfix diff --git a/_pytest/config.py b/_pytest/config.py index 499c8079d..ce7468f72 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -242,9 +242,10 @@ class PytestPluginManager(PluginManager): return opts def register(self, plugin, name=None): - if name == 'pytest_catchlog': - self._warn('pytest-catchlog plugin has been merged into the core, ' - 'please remove it from your requirements.') + if name in ['pytest_catchlog', 'pytest_capturelog']: + self._warn('{0} plugin has been merged into the core, ' + 'please remove it from your requirements.'.format( + name.replace('_', '-'))) return ret = super(PytestPluginManager, self).register(plugin, name) if ret: diff --git a/changelog/3004.bugfix b/changelog/3004.bugfix new file mode 100644 index 000000000..22f4fd1d7 --- /dev/null +++ b/changelog/3004.bugfix @@ -0,0 +1 @@ +The pytest-capturelog plugin is now also blacklisted, avoiding errors when running pytest with it still installed. diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 11c4ad43c..420070d91 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -114,14 +114,15 @@ def test_terminal_reporter_writer_attr(pytestconfig): assert terminal_reporter.writer is terminal_reporter._tw -def test_pytest_catchlog_deprecated(testdir): +@pytest.mark.parametrize('plugin', ['catchlog', 'capturelog']) +def test_pytest_catchlog_deprecated(testdir, plugin): testdir.makepyfile(""" def test_func(pytestconfig): - pytestconfig.pluginmanager.register(None, 'pytest_catchlog') - """) + pytestconfig.pluginmanager.register(None, 'pytest_{0}') + """.format(plugin)) res = testdir.runpytest() assert res.ret == 0 res.stdout.fnmatch_lines([ - "*pytest-catchlog plugin has been merged into the core*", + "*pytest-*log plugin has been merged into the core*", "*1 passed, 1 warnings*", ]) From cbdab02d050bb4f9780802e9e7b905008a8209c1 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 5 Dec 2017 20:05:35 +0100 Subject: [PATCH 7/9] Fix example in PR template --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index bf9fc199f..690426d68 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,7 +3,7 @@ Thanks for submitting a PR, your contribution is really appreciated! Here's a quick checklist that should be present in PRs: - [ ] Add a new news fragment into the changelog folder - * name it `$issue_id.$type` for example (588.bug) + * name it `$issue_id.$type` for example (588.bugfix) * if you don't have an issue_id change it to the pr id after creating the pr * ensure type is one of `removal`, `feature`, `bugfix`, `vendor`, `doc` or `trivial` * Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files." From 2a111ff700f295d9b27fb1a43219e08df62fc0bd Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 5 Dec 2017 20:41:57 +0000 Subject: [PATCH 8/9] Preparing release version 3.3.1 --- CHANGELOG.rst | 42 +++++++++++++++++++++++++++++++ changelog/2920.bugfix | 1 - changelog/2949.trivial | 1 - changelog/2956.bugfix | 1 - changelog/2957.bugfix | 1 - changelog/2963.doc | 1 - changelog/2971.bugfix | 1 - changelog/2984.bugfix | 1 - changelog/3004.bugfix | 1 - doc/en/announce/index.rst | 1 + doc/en/announce/release-3.3.1.rst | 25 ++++++++++++++++++ 11 files changed, 68 insertions(+), 8 deletions(-) delete mode 100644 changelog/2920.bugfix delete mode 100644 changelog/2949.trivial delete mode 100644 changelog/2956.bugfix delete mode 100644 changelog/2957.bugfix delete mode 100644 changelog/2963.doc delete mode 100644 changelog/2971.bugfix delete mode 100644 changelog/2984.bugfix delete mode 100644 changelog/3004.bugfix create mode 100644 doc/en/announce/release-3.3.1.rst diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7e7bfaf04..91189b9c6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,48 @@ .. towncrier release notes start +Pytest 3.3.1 (2017-12-05) +========================= + +Bug Fixes +--------- + +- Fix issue about ``-p no:`` having no effect. (`#2920 + `_) + +- Fix regression with warnings that contained non-strings in their arguments in + Python 2. (`#2956 `_) + +- Always escape null bytes when setting ``PYTEST_CURRENT_TEST``. (`#2957 + `_) + +- Fix ``ZeroDivisionError`` when using the ``testmon`` plugin when no tests + were actually collected. (`#2971 + `_) + +- Bring back ``TerminalReporter.writer`` as an alias to + ``TerminalReporter._tw``. This alias was removed by accident in the ``3.3.0`` + release. (`#2984 `_) + +- The pytest-capturelog plugin is now also blacklisted, avoiding errors when + running pytest with it still installed. (`#3004 + `_) + + +Improved Documentation +---------------------- + +- Fix broken link to plugin pytest-localserver. (`#2963 + `_) + + +Trivial/Internal Changes +------------------------ + +- Update github "bugs" link in CONTRIBUTING.rst (`#2949 + `_) + + Pytest 3.3.0 (2017-11-23) ========================= diff --git a/changelog/2920.bugfix b/changelog/2920.bugfix deleted file mode 100644 index 9c5217278..000000000 --- a/changelog/2920.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix issue about ``-p no:`` having no effect. diff --git a/changelog/2949.trivial b/changelog/2949.trivial deleted file mode 100644 index 39789e72b..000000000 --- a/changelog/2949.trivial +++ /dev/null @@ -1 +0,0 @@ -Update github "bugs" link in CONTRIBUTING.rst diff --git a/changelog/2956.bugfix b/changelog/2956.bugfix deleted file mode 100644 index 13717657b..000000000 --- a/changelog/2956.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix regression with warnings that contained non-strings in their arguments in Python 2. diff --git a/changelog/2957.bugfix b/changelog/2957.bugfix deleted file mode 100644 index 589665b69..000000000 --- a/changelog/2957.bugfix +++ /dev/null @@ -1 +0,0 @@ -Always escape null bytes when setting ``PYTEST_CURRENT_TEST``. diff --git a/changelog/2963.doc b/changelog/2963.doc deleted file mode 100644 index c9a1d661b..000000000 --- a/changelog/2963.doc +++ /dev/null @@ -1 +0,0 @@ -Fix broken link to plugin pytest-localserver. diff --git a/changelog/2971.bugfix b/changelog/2971.bugfix deleted file mode 100644 index 36684e8c8..000000000 --- a/changelog/2971.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix ``ZeroDivisionError`` when using the ``testmon`` plugin when no tests were actually collected. diff --git a/changelog/2984.bugfix b/changelog/2984.bugfix deleted file mode 100644 index 21f5748d5..000000000 --- a/changelog/2984.bugfix +++ /dev/null @@ -1 +0,0 @@ -Bring back ``TerminalReporter.writer`` as an alias to ``TerminalReporter._tw``. This alias was removed by accident in the ``3.3.0`` release. diff --git a/changelog/3004.bugfix b/changelog/3004.bugfix deleted file mode 100644 index 22f4fd1d7..000000000 --- a/changelog/3004.bugfix +++ /dev/null @@ -1 +0,0 @@ -The pytest-capturelog plugin is now also blacklisted, avoiding errors when running pytest with it still installed. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index 1a5f3760b..b6255bc6d 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-3.3.1 release-3.3.0 release-3.2.5 release-3.2.4 diff --git a/doc/en/announce/release-3.3.1.rst b/doc/en/announce/release-3.3.1.rst new file mode 100644 index 000000000..074c3d5ac --- /dev/null +++ b/doc/en/announce/release-3.3.1.rst @@ -0,0 +1,25 @@ +pytest-3.3.1 +======================================= + +pytest 3.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 http://doc.pytest.org/en/latest/changelog.html. + +Thanks to all who contributed to this release, among them: + +* Bruno Oliveira +* Daniel Hahler +* Eugene Prikazchikov +* Florian Bruhin +* Roland Puntaier +* Ronny Pfannschmidt +* Sebastian Rahlf +* Tom Viner + + +Happy testing, +The pytest Development Team From 88f2cc9b641bca41818918ef853b7d10dca6bcaa Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 5 Dec 2017 22:28:56 -0200 Subject: [PATCH 9/9] Small formatting fixes in CHANGELOG --- CHANGELOG.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 91189b9c6..eabd28be1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -31,7 +31,7 @@ Bug Fixes ``TerminalReporter._tw``. This alias was removed by accident in the ``3.3.0`` release. (`#2984 `_) -- The pytest-capturelog plugin is now also blacklisted, avoiding errors when +- The ``pytest-capturelog`` plugin is now also blacklisted, avoiding errors when running pytest with it still installed. (`#3004 `_) @@ -39,14 +39,14 @@ Bug Fixes Improved Documentation ---------------------- -- Fix broken link to plugin pytest-localserver. (`#2963 +- Fix broken link to plugin ``pytest-localserver``. (`#2963 `_) Trivial/Internal Changes ------------------------ -- Update github "bugs" link in CONTRIBUTING.rst (`#2949 +- Update github "bugs" link in ``CONTRIBUTING.rst`` (`#2949 `_)