From 1cecdf66198049c7ca48356d8349e2f07732764c Mon Sep 17 00:00:00 2001 From: Steffen Schroeder Date: Sat, 13 Jul 2019 16:06:56 +0200 Subject: [PATCH 01/17] Added checklinks to tox and release.py --- doc/en/conf.py | 13 +++++++++++++ scripts/release.py | 7 +++++++ tox.ini | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/doc/en/conf.py b/doc/en/conf.py index 1a6ef7ca8..c0c71cf05 100644 --- a/doc/en/conf.py +++ b/doc/en/conf.py @@ -112,6 +112,19 @@ pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] +# A list of regular expressions that match URIs that should not be checked when +# doing a linkcheck. +linkcheck_ignore = [ + "https://github.com/numpy/numpy/blob/master/doc/release/1.16.0-notes.rst#new-deprecations", + "https://blogs.msdn.microsoft.com/bharry/2017/06/28/testing-in-a-cloud-delivery-cadence/", + "http://pythontesting.net/framework/pytest-introduction/", + r"https://github.com/pytest-dev/pytest/issues/\d+", + r"https://github.com/pytest-dev/pytest/pull/\d+", +] + +# The number of worker threads to use when checking links (default=5). +linkcheck_workers = 5 + # -- Options for HTML output --------------------------------------------------- diff --git a/scripts/release.py b/scripts/release.py index 5009df359..884d9bfb1 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -79,12 +79,19 @@ def fix_formatting(): call(["pre-commit", "run", "--all-files"]) +def check_links(): + """Runs sphinx-build to check links""" + print(f"{Fore.CYAN}[generate.check_links] {Fore.RESET}Checking links") + check_call(["tox", "-e", "docs-checklinks"]) + + def pre_release(version): """Generates new docs, release announcements and creates a local tag.""" announce(version) regen() changelog(version, write_out=True) fix_formatting() + check_links() msg = "Preparing release version {}".format(version) check_call(["git", "commit", "-a", "-m", msg]) diff --git a/tox.ini b/tox.ini index b03941657..d1a34c264 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ envlist = doctesting py37-freeze docs + docs-checklinks [testenv] commands = @@ -66,6 +67,14 @@ deps = -r{toxinidir}/doc/en/requirements.txt commands = sphinx-build -W -b html . _build +[testenv:docs-checklinks] +basepython = python3 +usedevelop = True +changedir = doc/en +deps = -r{toxinidir}/doc/en/requirements.txt +commands = + sphinx-build -W --keep-going -b linkcheck . _build + [testenv:doctesting] basepython = python3 skipsdist = True From ceeb7bd0851e87b47bd54c88e3a8d9f04470baad Mon Sep 17 00:00:00 2001 From: Steffen Schroeder Date: Tue, 27 Aug 2019 21:00:48 +0200 Subject: [PATCH 02/17] Fixed broken links --- CHANGELOG.rst | 14 +++++++------- doc/en/announce/release-2.0.0.rst | 8 ++++---- doc/en/announce/release-2.0.1.rst | 2 +- doc/en/announce/release-2.2.0.rst | 6 +++--- doc/en/announce/release-2.3.0.rst | 10 +++++----- doc/en/announce/release-2.3.4.rst | 2 +- doc/en/announce/release-2.4.0.rst | 2 +- doc/en/announce/release-2.7.0.rst | 2 +- doc/en/announce/release-2.9.0.rst | 2 +- doc/en/fixture.rst | 6 +++--- doc/en/projects.rst | 1 - doc/en/talks.rst | 2 +- tox.ini | 2 +- 13 files changed, 29 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 375b5dabf..aa90006f1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3462,7 +3462,7 @@ Deprecations and Removals - ``pytest.approx`` no longer supports ``>``, ``>=``, ``<`` and ``<=`` operators to avoid surprising/inconsistent behavior. See `the approx docs - `_ for more + `_ for more information. (`#2003 `_) - All old-style specific behavior in current classes in the pytest's API is @@ -4819,7 +4819,7 @@ time or change existing behaviors in order to make them less surprising/more use * Fix (`#1422`_): junit record_xml_property doesn't allow multiple records with same name. -.. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing +.. _`traceback style docs`: https://pytest.org/en/latest/usage.html#modifying-python-traceback-printing .. _#1609: https://github.com/pytest-dev/pytest/issues/1609 .. _#1422: https://github.com/pytest-dev/pytest/issues/1422 @@ -5337,7 +5337,7 @@ time or change existing behaviors in order to make them less surprising/more use - add ability to set command line options by environment variable PYTEST_ADDOPTS. - added documentation on the new pytest-dev teams on bitbucket and - github. See https://pytest.org/latest/contributing.html . + github. See https://pytest.org/en/latest/contributing.html . Thanks to Anatoly for pushing and initial work on this. - fix issue650: new option ``--docttest-ignore-import-errors`` which @@ -6078,7 +6078,7 @@ Bug fixes: - yielded test functions will now have autouse-fixtures active but cannot accept fixtures as funcargs - it's anyway recommended to rather use the post-2.0 parametrize features instead of yield, see: - http://pytest.org/latest/example/parametrize.html + http://pytest.org/en/latest/example/parametrize.html - fix autouse-issue where autouse-fixtures would not be discovered if defined in an a/conftest.py file and tests in a/tests/test_some.py - fix issue226 - LIFO ordering for fixture teardowns @@ -6211,7 +6211,7 @@ Bug fixes: - pluginmanager.register(...) now raises ValueError if the plugin has been already registered or the name is taken -- fix issue159: improve http://pytest.org/latest/faq.html +- fix issue159: improve http://pytest.org/en/latest/faq.html especially with respect to the "magic" history, also mention pytest-django, trial and unittest integration. @@ -6324,7 +6324,7 @@ Bug fixes: or through plugin hooks. Also introduce a "--strict" option which will treat unregistered markers as errors allowing to avoid typos and maintain a well described set of markers - for your test suite. See exaples at http://pytest.org/latest/mark.html + for your test suite. See exaples at http://pytest.org/en/latest/mark.html and its links. - issue50: introduce "-m marker" option to select tests based on markers (this is a stricter and more predictable version of '-k' in that "-m" @@ -6507,7 +6507,7 @@ Bug fixes: - refinements to "collecting" output on non-ttys - refine internal plugin registration and --traceconfig output - introduce a mechanism to prevent/unregister plugins from the - command line, see http://pytest.org/plugins.html#cmdunregister + command line, see http://pytest.org/en/latest/plugins.html#cmdunregister - activate resultlog plugin by default - fix regression wrt yielded tests which due to the collection-before-running semantics were not diff --git a/doc/en/announce/release-2.0.0.rst b/doc/en/announce/release-2.0.0.rst index af745fc59..d9d90c09a 100644 --- a/doc/en/announce/release-2.0.0.rst +++ b/doc/en/announce/release-2.0.0.rst @@ -7,7 +7,7 @@ see below for summary and detailed lists. A lot of long-deprecated code has been removed, resulting in a much smaller and cleaner implementation. See the new docs with examples here: - http://pytest.org/2.0.0/index.html + http://pytest.org/en/latest/index.html A note on packaging: pytest used to part of the "py" distribution up until version py-1.3.4 but this has changed now: pytest-2.0.0 only @@ -36,12 +36,12 @@ New Features import pytest ; pytest.main(arglist, pluginlist) - see http://pytest.org/2.0.0/usage.html for details. + see http://pytest.org/en/latest/usage.html for details. - new and better reporting information in assert expressions if comparing lists, sequences or strings. - see http://pytest.org/2.0.0/assert.html#newreport + see http://pytest.org/en/latest/assert.html#newreport - new configuration through ini-files (setup.cfg or tox.ini recognized), for example:: @@ -50,7 +50,7 @@ New Features norecursedirs = .hg data* # don't ever recurse in such dirs addopts = -x --pyargs # add these command line options by default - see http://pytest.org/2.0.0/customize.html + see http://pytest.org/en/latest/customize.html - improved standard unittest support. In general py.test should now better be able to run custom unittest.TestCases like twisted trial diff --git a/doc/en/announce/release-2.0.1.rst b/doc/en/announce/release-2.0.1.rst index 2f41ef943..f86537e1d 100644 --- a/doc/en/announce/release-2.0.1.rst +++ b/doc/en/announce/release-2.0.1.rst @@ -57,7 +57,7 @@ Changes between 2.0.0 and 2.0.1 - refinements to "collecting" output on non-ttys - refine internal plugin registration and --traceconfig output - introduce a mechanism to prevent/unregister plugins from the - command line, see http://pytest.org/latest/plugins.html#cmdunregister + command line, see http://pytest.org/en/latest/plugins.html#cmdunregister - activate resultlog plugin by default - fix regression wrt yielded tests which due to the collection-before-running semantics were not diff --git a/doc/en/announce/release-2.2.0.rst b/doc/en/announce/release-2.2.0.rst index 20bfe0a19..79e4dfd15 100644 --- a/doc/en/announce/release-2.2.0.rst +++ b/doc/en/announce/release-2.2.0.rst @@ -9,7 +9,7 @@ with these improvements: - new @pytest.mark.parametrize decorator to run tests with different arguments - new metafunc.parametrize() API for parametrizing arguments independently - - see examples at http://pytest.org/latest/example/parametrize.html + - see examples at http://pytest.org/en/latest/example/parametrize.html - NOTE that parametrize() related APIs are still a bit experimental and might change in future releases. @@ -18,7 +18,7 @@ with these improvements: - "-m markexpr" option for selecting tests according to their mark - a new "markers" ini-variable for registering test markers for your project - the new "--strict" bails out with an error if using unregistered markers. - - see examples at http://pytest.org/latest/example/markers.html + - see examples at http://pytest.org/en/latest/example/markers.html * duration profiling: new "--duration=N" option showing the N slowest test execution or setup/teardown calls. This is most useful if you want to @@ -78,7 +78,7 @@ Changes between 2.1.3 and 2.2.0 or through plugin hooks. Also introduce a "--strict" option which will treat unregistered markers as errors allowing to avoid typos and maintain a well described set of markers - for your test suite. See examples at http://pytest.org/latest/mark.html + for your test suite. See examples at http://pytest.org/en/latest/mark.html and its links. - issue50: introduce "-m marker" option to select tests based on markers (this is a stricter and more predictable version of "-k" in that "-m" diff --git a/doc/en/announce/release-2.3.0.rst b/doc/en/announce/release-2.3.0.rst index 061aa025c..5fb253670 100644 --- a/doc/en/announce/release-2.3.0.rst +++ b/doc/en/announce/release-2.3.0.rst @@ -13,12 +13,12 @@ re-useable fixture design. For detailed info and tutorial-style examples, see: - http://pytest.org/latest/fixture.html + http://pytest.org/en/latest/fixture.html Moreover, there is now support for using pytest fixtures/funcargs with unittest-style suites, see here for examples: - http://pytest.org/latest/unittest.html + http://pytest.org/en/latest/unittest.html Besides, more unittest-test suites are now expected to "simply work" with pytest. @@ -29,11 +29,11 @@ pytest-2.2.4. If you are interested in the precise reasoning (including examples) of the pytest-2.3 fixture evolution, please consult -http://pytest.org/latest/funcarg_compare.html +http://pytest.org/en/latest/funcarg_compare.html For general info on installation and getting started: - http://pytest.org/latest/getting-started.html + http://pytest.org/en/latest/getting-started.html Docs and PDF access as usual at: @@ -94,7 +94,7 @@ Changes between 2.2.4 and 2.3.0 - pluginmanager.register(...) now raises ValueError if the plugin has been already registered or the name is taken -- fix issue159: improve http://pytest.org/latest/faq.html +- fix issue159: improve http://pytest.org/en/latest/faq.html especially with respect to the "magic" history, also mention pytest-django, trial and unittest integration. diff --git a/doc/en/announce/release-2.3.4.rst b/doc/en/announce/release-2.3.4.rst index e2e8cb143..b00430f94 100644 --- a/doc/en/announce/release-2.3.4.rst +++ b/doc/en/announce/release-2.3.4.rst @@ -16,7 +16,7 @@ comes with the following fixes and features: - yielded test functions will now have autouse-fixtures active but cannot accept fixtures as funcargs - it's anyway recommended to rather use the post-2.0 parametrize features instead of yield, see: - http://pytest.org/latest/example/parametrize.html + http://pytest.org/en/latest/example/parametrize.html - fix autouse-issue where autouse-fixtures would not be discovered if defined in an a/conftest.py file and tests in a/tests/test_some.py - fix issue226 - LIFO ordering for fixture teardowns diff --git a/doc/en/announce/release-2.4.0.rst b/doc/en/announce/release-2.4.0.rst index 1b0168841..6cd14bc2d 100644 --- a/doc/en/announce/release-2.4.0.rst +++ b/doc/en/announce/release-2.4.0.rst @@ -7,7 +7,7 @@ from a few supposedly very minor incompatibilities. See below for a full list of details. A few feature highlights: - new yield-style fixtures `pytest.yield_fixture - `_, allowing to use + `_, allowing to use existing with-style context managers in fixture functions. - improved pdb support: ``import pdb ; pdb.set_trace()`` now works diff --git a/doc/en/announce/release-2.7.0.rst b/doc/en/announce/release-2.7.0.rst index d63081edb..8952ff50f 100644 --- a/doc/en/announce/release-2.7.0.rst +++ b/doc/en/announce/release-2.7.0.rst @@ -52,7 +52,7 @@ holger krekel - add ability to set command line options by environment variable PYTEST_ADDOPTS. - added documentation on the new pytest-dev teams on bitbucket and - github. See https://pytest.org/latest/contributing.html . + github. See https://pytest.org/en/latest/contributing.html . Thanks to Anatoly for pushing and initial work on this. - fix issue650: new option ``--docttest-ignore-import-errors`` which diff --git a/doc/en/announce/release-2.9.0.rst b/doc/en/announce/release-2.9.0.rst index 05d9a394f..9e0856690 100644 --- a/doc/en/announce/release-2.9.0.rst +++ b/doc/en/announce/release-2.9.0.rst @@ -131,7 +131,7 @@ The py.test Development Team with same name. -.. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing +.. _`traceback style docs`: https://pytest.org/en/latest/usage.html#modifying-python-traceback-printing .. _#1422: https://github.com/pytest-dev/pytest/issues/1422 .. _#1379: https://github.com/pytest-dev/pytest/issues/1379 diff --git a/doc/en/fixture.rst b/doc/en/fixture.rst index 6e1e554bf..08305a5cc 100644 --- a/doc/en/fixture.rst +++ b/doc/en/fixture.rst @@ -9,9 +9,9 @@ pytest fixtures: explicit, modular, scalable -.. _`xUnit`: http://en.wikipedia.org/wiki/XUnit -.. _`purpose of test fixtures`: http://en.wikipedia.org/wiki/Test_fixture#Software -.. _`Dependency injection`: http://en.wikipedia.org/wiki/Dependency_injection +.. _`xUnit`: https://en.wikipedia.org/wiki/XUnit +.. _`purpose of test fixtures`: https://en.wikipedia.org/wiki/Test_fixture#Software +.. _`Dependency injection`: https://en.wikipedia.org/wiki/Dependency_injection The `purpose of test fixtures`_ is to provide a fixed baseline upon which tests can reliably and repeatedly execute. pytest fixtures diff --git a/doc/en/projects.rst b/doc/en/projects.rst index 751d0abe9..2febcd24b 100644 --- a/doc/en/projects.rst +++ b/doc/en/projects.rst @@ -73,7 +73,6 @@ Some organisations using pytest * `Square Kilometre Array, Cape Town `_ * `Some Mozilla QA people `_ use pytest to distribute their Selenium tests -* `Tandberg `_ * `Shootq `_ * `Stups department of Heinrich Heine University Duesseldorf `_ * cellzome diff --git a/doc/en/talks.rst b/doc/en/talks.rst index 04eb97c7f..16bdd665b 100644 --- a/doc/en/talks.rst +++ b/doc/en/talks.rst @@ -64,7 +64,7 @@ Talks and blog postings - `pytest introduction from Brian Okken (January 2013) `_ -- pycon australia 2012 pytest talk from Brianna Laugher (`video `_, `slides `_, `code `_) +- pycon australia 2012 pytest talk from Brianna Laugher (`video `_, `slides `_, `code `_) - `pycon 2012 US talk video from Holger Krekel `_ - `monkey patching done right`_ (blog post, consult `monkeypatch plugin`_ for up-to-date API) diff --git a/tox.ini b/tox.ini index d1a34c264..2506201fd 100644 --- a/tox.ini +++ b/tox.ini @@ -73,7 +73,7 @@ usedevelop = True changedir = doc/en deps = -r{toxinidir}/doc/en/requirements.txt commands = - sphinx-build -W --keep-going -b linkcheck . _build + sphinx-build -W -q --keep-going -b linkcheck . _build [testenv:doctesting] basepython = python3 From 36ef545b2dcfdbfd1bf10fd65aa54f229b199349 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 19 Nov 2019 14:04:21 -0300 Subject: [PATCH 03/17] Improve instructions on how to write CHANGELOG entries This makes easier for contributors to get the CHANGELOG entry right the first time. --- .github/PULL_REQUEST_TEMPLATE.md | 8 ++++++++ changelog/README.rst | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7436f7146..7f9aa9556 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -11,5 +11,13 @@ Here is a quick checklist that should be present in PRs. Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please: - [ ] Create a new changelog file in the `changelog` folder, with a name like `..rst`. See [changelog/README.rst](https://github.com/pytest-dev/pytest/blob/master/changelog/README.rst) for details. + + Write sentences in the **past or present tense**, examples: + + * *Improved verbose diff output with sequences.* + * *Terminal summary statistics now use multiple colors.* + + Also make sure to end the sentence with a `.`. + - [ ] Add yourself to `AUTHORS` in alphabetical order. --> diff --git a/changelog/README.rst b/changelog/README.rst index 5c182758b..3e464508a 100644 --- a/changelog/README.rst +++ b/changelog/README.rst @@ -1,12 +1,14 @@ This directory contains "newsfragments" which are short files that contain a small **ReST**-formatted text that will be added to the next ``CHANGELOG``. -The ``CHANGELOG`` will be read by users, so this description should be aimed to pytest users +The ``CHANGELOG`` will be read by **users**, so this description should be aimed to pytest users instead of describing internal changes which are only relevant to the developers. -Make sure to use full sentences with correct case and punctuation, for example:: +Make sure to use full sentences in the **past or present tense** and use punctuation, examples:: - Fix issue with non-ascii messages from the ``warnings`` module. + Improved verbose diff output with sequences. + + Terminal summary statistics now use multiple colors. Each file should be named like ``..rst``, where ```` is an issue number, and ```` is one of: From 2228ccbfb412e58138e88101876187008bb22346 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 3 Nov 2019 23:02:30 +0100 Subject: [PATCH 04/17] pytester: reset log output in _match_lines (#70) This is necessary for when using e.g. `no_fnmatch_line` after it. Factor it out into `_fail`. (cherry picked from commit aade7ed0045ba32557ef8565cbab28a2c91053a7) Ref: https://github.com/pytest-dev/pytest/pull/5914#issuecomment-549182242 --- changelog/5914.bugfix.rst | 1 + src/_pytest/pytester.py | 38 +++++++++++++++++++++----------------- testing/test_pytester.py | 10 +++++++++- 3 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 changelog/5914.bugfix.rst diff --git a/changelog/5914.bugfix.rst b/changelog/5914.bugfix.rst new file mode 100644 index 000000000..b62b0b3c0 --- /dev/null +++ b/changelog/5914.bugfix.rst @@ -0,0 +1 @@ +pytester: fix ``no_fnmatch_line`` when used after positive matching. diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 02414a299..bacb1c23d 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -1438,8 +1438,10 @@ class LineMatcher: self._log("{:>{width}}".format("and:", width=wnick), repr(nextline)) extralines.append(nextline) else: - self._log("remains unmatched: {!r}".format(line)) - pytest.fail(self._log_text.lstrip()) + msg = "remains unmatched: {!r}".format(line) + self._log(msg) + self._fail(msg) + self._log_output = [] def no_fnmatch_line(self, pat): """Ensure captured lines do not match the given pattern, using ``fnmatch.fnmatch``. @@ -1465,18 +1467,20 @@ class LineMatcher: __tracebackhide__ = True nomatch_printed = False wnick = len(match_nickname) + 1 - try: - for line in self.lines: - if match_func(line, pat): - self._log("%s:" % match_nickname, repr(pat)) - self._log("{:>{width}}".format("with:", width=wnick), repr(line)) - pytest.fail(self._log_text.lstrip()) - else: - if not nomatch_printed: - self._log( - "{:>{width}}".format("nomatch:", width=wnick), repr(pat) - ) - nomatch_printed = True - self._log("{:>{width}}".format("and:", width=wnick), repr(line)) - finally: - self._log_output = [] + for line in self.lines: + if match_func(line, pat): + msg = "{}: {!r}".format(match_nickname, pat) + self._log(msg) + self._log("{:>{width}}".format("with:", width=wnick), repr(line)) + self._fail(msg) + else: + if not nomatch_printed: + self._log("{:>{width}}".format("nomatch:", width=wnick), repr(pat)) + nomatch_printed = True + self._log("{:>{width}}".format("and:", width=wnick), repr(line)) + self._log_output = [] + + def _fail(self, msg): + log_text = self._log_text + self._log_output = [] + pytest.fail(log_text) diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 758e999dc..5bdbacdd0 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -530,7 +530,7 @@ def test_no_matching(function): ] else: assert obtained == [ - "nomatch: '{}'".format(good_pattern), + " nomatch: '{}'".format(good_pattern), " and: 'cachedir: .pytest_cache'", " and: 'collecting ... collected 1 item'", " and: ''", @@ -542,6 +542,14 @@ def test_no_matching(function): func(bad_pattern) # bad pattern does not match any line: passes +def test_no_matching_after_match(): + lm = LineMatcher(["1", "2", "3"]) + lm.fnmatch_lines(["1", "3"]) + with pytest.raises(pytest.fail.Exception) as e: + lm.no_fnmatch_line("*") + assert str(e.value).splitlines() == ["fnmatch: '*'", " with: '1'"] + + def test_pytester_addopts(request, monkeypatch): monkeypatch.setenv("PYTEST_ADDOPTS", "--orig-unused") From 8c65eae5f4cb6d023b1720e3fcf65e03cc0d858a Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 19 Nov 2019 21:12:30 -0800 Subject: [PATCH 05/17] Fix rendering of Before/After in changelog Apparently the version of sphinx that rtd uses is a little more strict about whether an anonymous `code-block` can happen --- CHANGELOG.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a63e6f838..9ab3c871e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -113,7 +113,7 @@ Improvements Before: - .. code-block:: + .. code-block:: pytest E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...] E Right contains 3 more items, first extra item: ' ' @@ -129,7 +129,7 @@ Improvements After: - .. code-block:: + .. code-block:: pytest E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...] E Right contains 3 more items, first extra item: ' ' From af9dfc604deb490431a790d89fba7dfae107a079 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 20 Nov 2019 07:05:31 -0300 Subject: [PATCH 06/17] Introduce 5934 in CHANGELOG and fix "pytest" blocks --- CHANGELOG.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9ab3c871e..0f53fe33a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -113,7 +113,7 @@ Improvements Before: - .. code-block:: pytest + :: E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...] E Right contains 3 more items, first extra item: ' ' @@ -129,7 +129,7 @@ Improvements After: - .. code-block:: pytest + :: E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...] E Right contains 3 more items, first extra item: ' ' @@ -145,6 +145,8 @@ Improvements E ] +- `#5934 `_: ``repr`` of ``ExceptionInfo`` objects has been improved to honor the ``__repr__`` method of the underlying exception. + - `#5936 `_: Display untruncated assertion message with ``-vv``. From fe69a2cfb7d834ca6bf25bc69b9331f49ca3d30d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 20 Nov 2019 07:06:11 -0300 Subject: [PATCH 07/17] Delete 5934.feature.rst included in the wrong folder by accident --- doc/5934.feature.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 doc/5934.feature.rst diff --git a/doc/5934.feature.rst b/doc/5934.feature.rst deleted file mode 100644 index 17c0b1737..000000000 --- a/doc/5934.feature.rst +++ /dev/null @@ -1 +0,0 @@ -``repr`` of ``ExceptionInfo`` objects has been improved to honor the ``__repr__`` method of the underlying exception. From be722652f0b63411a6c9e9e5a193cac129404d24 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 20 Nov 2019 23:20:29 +0100 Subject: [PATCH 08/17] docs: configure default_role=literal This configures the default role for interpreted text (single backticks), avoiding the need to check for / enforce double backticks. Fixes also one instance in the existing changelog: - Detect `pytest_` prefixed hooks using the internal plugin manager since ``pluggy`` is deprecating the ``implprefix`` argument to ``PluginManager``. (`#3487 `_) --- .pre-commit-config.yaml | 4 ---- doc/en/conf.py | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8210ef5d5..d4196152f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,10 +37,6 @@ repos: hooks: - id: pyupgrade args: [--py3-plus] -- repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.4.0 - hooks: - - id: rst-backticks - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.740 hooks: diff --git a/doc/en/conf.py b/doc/en/conf.py index 1a6ef7ca8..008499c0e 100644 --- a/doc/en/conf.py +++ b/doc/en/conf.py @@ -92,7 +92,7 @@ exclude_patterns = [ # The reST default role (used for this markup: `text`) to use for all documents. -# default_role = None +default_role = "literal" # If true, '()' will be appended to :func: etc. cross-reference text. # add_function_parentheses = True From b96e0a71a6ce4130b480b6c601befadbeec5dfe5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 21 Nov 2019 01:23:36 +0100 Subject: [PATCH 09/17] pytester: LineMatcher: __tracebackhide__ with _fail Follow-up to 2228ccb (gone lost in resolving the conflict). --- src/_pytest/pytester.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index bacb1c23d..f44a69a95 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -1481,6 +1481,7 @@ class LineMatcher: self._log_output = [] def _fail(self, msg): + __tracebackhide__ = True log_text = self._log_text self._log_output = [] pytest.fail(log_text) From 6659fe0edcff7fdedd8b28509f4e5e050c42edfa Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 21 Nov 2019 06:20:39 +0100 Subject: [PATCH 10/17] CHANGELOG: two minor fixes/improvements --- CHANGELOG.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0f53fe33a..527d54316 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -157,7 +157,7 @@ Improvements immutable and avoid accidental modifications. -- `#6023 `_: ``pytest.main`` now returns a ``pytest.ExitCode`` instance now, except for when custom exit codes are used (where it returns ``int`` then still). +- `#6023 `_: ``pytest.main`` returns a ``pytest.ExitCode`` instance now, except for when custom exit codes are used (where it returns ``int`` then still). - `#6026 `_: Align prefixes in output of pytester's ``LineMatcher``. @@ -169,7 +169,7 @@ Improvements - `#6069 `_: ``pytester.spawn`` does not skip/xfail tests on FreeBSD anymore unconditionally. -- `#6097 `_: The "[XXX%]" indicator in the test summary is now colored according to the final (new) multi-colored line's main color. +- `#6097 `_: The "[...%]" indicator in the test summary is now colored according to the final (new) multi-colored line's main color. - `#6116 `_: Added ``--co`` as a synonym to ``--collect-only``. From 64eb9ea670fd4d31e46e41ee397933fcad05886d Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 11:50:40 +0000 Subject: [PATCH 11/17] Modify test for new expected behaviour --- testing/test_runner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/test_runner.py b/testing/test_runner.py index 86e9bddff..301e11898 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -900,9 +900,9 @@ def test_store_except_info_on_error(): # The next run should clear the exception info stored by the previous run ItemMightRaise.raise_error = False runner.pytest_runtest_call(ItemMightRaise()) - assert sys.last_type is None - assert sys.last_value is None - assert sys.last_traceback is None + assert not hasattr(sys, "last_type") + assert not hasattr(sys, "last_value") + assert not hasattr(sys, "last_traceback") def test_current_test_env_var(testdir, monkeypatch): From 8f2fd8ffc039f45a8daaedd62e6a2ca9af2542f6 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 20 Nov 2019 20:26:45 -0300 Subject: [PATCH 12/17] Add develop instructions to CONTRIBUTING From: https://github.com/pytest-dev/pytest/pull/6244 --- .gitignore | 1 + CONTRIBUTING.rst | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index 27bd93c7b..fc61c6ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ dist/ issue/ env/ .env/ +.venv/ 3rdparty/ .tox .cache diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 8e59191ab..a3ae731e4 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -262,6 +262,19 @@ Here is a simple overview, with pytest-specific bits: When committing, ``pre-commit`` will re-format the files if necessary. +#. If instead of using ``tox`` you prefer to run the tests directly, then we suggest to create a virtual environment and use + an editable install with the ``testing`` extra:: + + $ python3 -m venv .venv + $ source .venv/bin/activate # Linux + $ .venv/Scripts/activate.bat # Windows + $ pip install -e ".[testing]" + + Afterwards, you can edit the files and run pytest normally:: + + $ pytest testing/test_config.py + + #. Commit and push once your tests pass and you are happy with your change(s):: $ git commit -a -m "" From 2ffbe41ae526b5367fca798e405fceab9bc57228 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:06:47 +0000 Subject: [PATCH 13/17] clear sys.last_traceback via del instead of = None --- src/_pytest/runner.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index c383146c3..67e28e905 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -121,7 +121,12 @@ def pytest_runtest_setup(item): def pytest_runtest_call(item): _update_current_test_var(item, "call") - sys.last_type, sys.last_value, sys.last_traceback = (None, None, None) + try: + del sys.last_type + del sys.last_value + del sys.last_traceback + except AttributeError: + pass try: item.runtest() except Exception: From 9d1082bd302832fe7289dfbed53a81a17eccf05c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:13:36 +0000 Subject: [PATCH 14/17] Add changelog file. --- changelog/6255.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/6255.bugfix.rst diff --git a/changelog/6255.bugfix.rst b/changelog/6255.bugfix.rst new file mode 100644 index 000000000..831187feb --- /dev/null +++ b/changelog/6255.bugfix.rst @@ -0,0 +1,3 @@ +Clear the ``sys.last_traceback``, ``sys.last_type`` and ``sys.last_value`` +attributes by deleting them instead of setting them to ``None``. This better +matches the behaviour of the Python standard library. From 8d686a8e460fe8dd513efe2632481587ce0d4ab9 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:14:19 +0000 Subject: [PATCH 15/17] Add self to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 14c465571..6e2f472fe 100644 --- a/AUTHORS +++ b/AUTHORS @@ -165,6 +165,7 @@ Marcelo Duarte Trevisani Marcin Bachry Marco Gorelli Mark Abramowitz +Mark Dickinson Markus Unterwaditzer Martijn Faassen Martin Altmayer From dbb8c146f041b4ffaa704097007d8bb1f160d990 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:22:34 +0000 Subject: [PATCH 16/17] Use proper reST attribute markup. --- changelog/6255.bugfix.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog/6255.bugfix.rst b/changelog/6255.bugfix.rst index 831187feb..6eb064ef3 100644 --- a/changelog/6255.bugfix.rst +++ b/changelog/6255.bugfix.rst @@ -1,3 +1,4 @@ -Clear the ``sys.last_traceback``, ``sys.last_type`` and ``sys.last_value`` -attributes by deleting them instead of setting them to ``None``. This better -matches the behaviour of the Python standard library. +Clear the :py:attr:`sys.last_traceback`, :py:attr:`sys.last_type` +and :py:attr:`sys.last_value` attributes by deleting them instead +of setting them to ``None``. This better matches the behaviour of +the Python standard library. From 82424c92708ed6fe9fba83ff4cbc3ce128e13494 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:37:17 +0000 Subject: [PATCH 17/17] Fix reST markup. --- changelog/6255.bugfix.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/changelog/6255.bugfix.rst b/changelog/6255.bugfix.rst index 6eb064ef3..831187feb 100644 --- a/changelog/6255.bugfix.rst +++ b/changelog/6255.bugfix.rst @@ -1,4 +1,3 @@ -Clear the :py:attr:`sys.last_traceback`, :py:attr:`sys.last_type` -and :py:attr:`sys.last_value` attributes by deleting them instead -of setting them to ``None``. This better matches the behaviour of -the Python standard library. +Clear the ``sys.last_traceback``, ``sys.last_type`` and ``sys.last_value`` +attributes by deleting them instead of setting them to ``None``. This better +matches the behaviour of the Python standard library.