From 2802135741a69fac1a22fa29832cd9b5605d87d1 Mon Sep 17 00:00:00 2001 From: Oliver Bestwalter Date: Tue, 19 Sep 2017 12:41:12 +0200 Subject: [PATCH 1/4] fix 'DoctestItem' object has no attribute '_fixtureinfo' * doxtests don't seem to have this attribute, so nothing will be written in that case. * tried to be a good boy scout and tidied up surrounding code a bit (comments, shadowed/unused names, removed random new lines, naming things) --- _pytest/python.py | 38 +++++++++++------------- changelog/2788.bugfix | 1 + testing/python/show_fixtures_per_test.py | 21 +++++++++++++ 3 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 changelog/2788.bugfix diff --git a/_pytest/python.py b/_pytest/python.py index e7bb9ad62..6c130f93e 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -979,50 +979,48 @@ def _show_fixtures_per_test(config, session): tw = _pytest.config.create_terminal_writer(config) verbose = config.getvalue("verbose") - def get_best_rel(func): + def get_best_relpath(func): loc = getlocation(func, curdir) return curdir.bestrelpath(loc) def write_fixture(fixture_def): argname = fixture_def.argname - if verbose <= 0 and argname.startswith("_"): return if verbose > 0: - bestrel = get_best_rel(fixture_def.func) + bestrel = get_best_relpath(fixture_def.func) funcargspec = "{0} -- {1}".format(argname, bestrel) else: funcargspec = argname tw.line(funcargspec, green=True) - fixture_doc = fixture_def.func.__doc__ - if fixture_doc: write_docstring(tw, fixture_doc) else: tw.line(' no docstring available', red=True) def write_item(item): - name2fixturedefs = item._fixtureinfo.name2fixturedefs - - if not name2fixturedefs: - # The given test item does not use any fixtures + try: + info = item._fixtureinfo + except AttributeError: + # doctests items have no _fixtureinfo attribute + return + if not info.name2fixturedefs: + # this test item does not use any fixtures return - bestrel = get_best_rel(item.function) - tw.line() tw.sep('-', 'fixtures used by {0}'.format(item.name)) - tw.sep('-', '({0})'.format(bestrel)) - for argname, fixture_defs in sorted(name2fixturedefs.items()): - assert fixture_defs is not None - if not fixture_defs: + tw.sep('-', '({0})'.format(get_best_relpath(item.function))) + # dict key not used in loop but needed for sorting + for _, fixturedefs in sorted(info.name2fixturedefs.items()): + assert fixturedefs is not None + if not fixturedefs: continue - # The last fixture def item in the list is expected - # to be the one used by the test item - write_fixture(fixture_defs[-1]) + # last item is expected to be the one used by the test item + write_fixture(fixturedefs[-1]) - for item in session.items: - write_item(item) + for session_item in session.items: + write_item(session_item) def showfixtures(config): diff --git a/changelog/2788.bugfix b/changelog/2788.bugfix new file mode 100644 index 000000000..4069bb6e6 --- /dev/null +++ b/changelog/2788.bugfix @@ -0,0 +1 @@ +When running ``pytest --fixtures-per-test``: don't crash if an item has no _fixtureinfo attribute (e.g. doctests) diff --git a/testing/python/show_fixtures_per_test.py b/testing/python/show_fixtures_per_test.py index 18563e818..741f33946 100644 --- a/testing/python/show_fixtures_per_test.py +++ b/testing/python/show_fixtures_per_test.py @@ -135,3 +135,24 @@ def test_verbose_include_private_fixtures_and_loc(testdir): 'arg3 -- test_verbose_include_private_fixtures_and_loc.py:3', ' arg3 from testmodule', ]) + + +def test_doctest_items(testdir): + testdir.makepyfile(''' + def foo(): + """ + >>> 1 + 1 + 2 + """ + ''') + testdir.maketxtfile(''' + >>> 1 + 1 + 2 + ''') + result = testdir.runpytest("--fixtures-per-test", "--doctest-modules", + "--doctest-glob=*.txt", "-v") + assert result.ret == 0 + + result.stdout.fnmatch_lines([ + '*collected 2 items*', + ]) From 58aaabbb10c7c044ed09b7756c1b5501556f9524 Mon Sep 17 00:00:00 2001 From: Oliver Bestwalter Date: Tue, 19 Sep 2017 16:57:16 +0200 Subject: [PATCH 2/4] fix tox documentation link --- CONTRIBUTING.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index fa317fd1b..917ce3c33 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -120,7 +120,7 @@ the following: - PyPI presence with a ``setup.py`` that contains a license, ``pytest-`` prefixed name, version number, authors, short and long description. -- a ``tox.ini`` for running tests using `tox `_. +- a ``tox.ini`` for running tests using `tox `_. - a ``README.txt`` describing how to use the plugin and on which platforms it runs. From 7093d8f65e48a0c944d1688f9d80d7e8f51b6b8b Mon Sep 17 00:00:00 2001 From: Xuan Luong Date: Sat, 30 Sep 2017 18:36:09 -0400 Subject: [PATCH 3/4] Add example of -k 'not test' in help text --- _pytest/mark.py | 3 ++- changelog/1442.doc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelog/1442.doc diff --git a/_pytest/mark.py b/_pytest/mark.py index d9af0ffaa..e4b6238eb 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -91,7 +91,8 @@ def pytest_addoption(parser): "where all names are substring-matched against test names " "and their parent classes. Example: -k 'test_method or test_" "other' matches all test functions and classes whose name " - "contains 'test_method' or 'test_other'. " + "contains 'test_method' or 'test_other', while -k 'not test_method' " + "matches those that don't contain 'test_method' in their names. " "Additionally keywords are matched to classes and functions " "containing extra names in their 'extra_keyword_matches' set, " "as well as functions which have names assigned directly to them." diff --git a/changelog/1442.doc b/changelog/1442.doc new file mode 100644 index 000000000..62ccf7504 --- /dev/null +++ b/changelog/1442.doc @@ -0,0 +1 @@ +In help text of ``-k`` option, add example of using ``not`` to not select certain tests whose names match the provided expression. \ No newline at end of file From 6b91bc88de36e3c75da5ab1b7480cbe067eed57b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 3 Oct 2017 21:42:34 +0000 Subject: [PATCH 4/4] Preparing release version 3.2.3 --- CHANGELOG.rst | 40 +++++++++++++++++++++++++++++++ changelog/1442.doc | 1 - changelog/1548.doc | 1 - changelog/2722.trivial | 1 - changelog/2748.bugfix | 1 - changelog/2758.bugfix | 1 - changelog/2765.trivial | 1 - changelog/2788.bugfix | 1 - doc/en/announce/index.rst | 1 + doc/en/announce/release-3.2.3.rst | 23 ++++++++++++++++++ doc/en/parametrize.rst | 1 - doc/en/skipping.rst | 6 ++--- 12 files changed, 67 insertions(+), 11 deletions(-) delete mode 100644 changelog/1442.doc delete mode 100644 changelog/1548.doc delete mode 100644 changelog/2722.trivial delete mode 100644 changelog/2748.bugfix delete mode 100644 changelog/2758.bugfix delete mode 100644 changelog/2765.trivial delete mode 100644 changelog/2788.bugfix create mode 100644 doc/en/announce/release-3.2.3.rst diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 829f691ad..28269a311 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,46 @@ .. towncrier release notes start +Pytest 3.2.3 (2017-10-03) +========================= + +Bug Fixes +--------- + +- Fix crash in tab completion when no prefix is given. (`#2748 + `_) + +- The equality checking function (``__eq__``) of ``MarkDecorator`` returns + ``False`` if one object is not an instance of ``MarkDecorator``. (`#2758 + `_) + +- When running ``pytest --fixtures-per-test``: don't crash if an item has no + _fixtureinfo attribute (e.g. doctests) (`#2788 + `_) + + +Improved Documentation +---------------------- + +- In help text of ``-k`` option, add example of using ``not`` to not select + certain tests whose names match the provided expression. (`#1442 + `_) + +- Add note in ``parametrize.rst`` about calling ``metafunc.parametrize`` + multiple times. (`#1548 `_) + + +Trivial/Internal Changes +------------------------ + +- Set ``xfail_strict=True`` in pytest's own test suite to catch expected + failures as soon as they start to pass. (`#2722 + `_) + +- Fix typo in example of passing a callable to markers (in example/markers.rst) + (`#2765 `_) + + Pytest 3.2.2 (2017-09-06) ========================= diff --git a/changelog/1442.doc b/changelog/1442.doc deleted file mode 100644 index 62ccf7504..000000000 --- a/changelog/1442.doc +++ /dev/null @@ -1 +0,0 @@ -In help text of ``-k`` option, add example of using ``not`` to not select certain tests whose names match the provided expression. \ No newline at end of file diff --git a/changelog/1548.doc b/changelog/1548.doc deleted file mode 100644 index 84ad8f10c..000000000 --- a/changelog/1548.doc +++ /dev/null @@ -1 +0,0 @@ -Add note in ``parametrize.rst`` about calling ``metafunc.parametrize`` multiple times. \ No newline at end of file diff --git a/changelog/2722.trivial b/changelog/2722.trivial deleted file mode 100644 index 2c0ccd7b1..000000000 --- a/changelog/2722.trivial +++ /dev/null @@ -1 +0,0 @@ -Set ``xfail_strict=True`` in pytest's own test suite to catch expected failures as soon as they start to pass. diff --git a/changelog/2748.bugfix b/changelog/2748.bugfix deleted file mode 100644 index b5b6f5839..000000000 --- a/changelog/2748.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix crash in tab completion when no prefix is given. diff --git a/changelog/2758.bugfix b/changelog/2758.bugfix deleted file mode 100644 index 12e4046b8..000000000 --- a/changelog/2758.bugfix +++ /dev/null @@ -1 +0,0 @@ -The equality checking function (``__eq__``) of ``MarkDecorator`` returns ``False`` if one object is not an instance of ``MarkDecorator``. \ No newline at end of file diff --git a/changelog/2765.trivial b/changelog/2765.trivial deleted file mode 100644 index 01110b852..000000000 --- a/changelog/2765.trivial +++ /dev/null @@ -1 +0,0 @@ -Fix typo in example of passing a callable to markers (in example/markers.rst) \ No newline at end of file diff --git a/changelog/2788.bugfix b/changelog/2788.bugfix deleted file mode 100644 index 4069bb6e6..000000000 --- a/changelog/2788.bugfix +++ /dev/null @@ -1 +0,0 @@ -When running ``pytest --fixtures-per-test``: don't crash if an item has no _fixtureinfo attribute (e.g. doctests) diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index a822adda5..58b9aeec7 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-3.2.3 release-3.2.2 release-3.2.1 release-3.2.0 diff --git a/doc/en/announce/release-3.2.3.rst b/doc/en/announce/release-3.2.3.rst new file mode 100644 index 000000000..589374974 --- /dev/null +++ b/doc/en/announce/release-3.2.3.rst @@ -0,0 +1,23 @@ +pytest-3.2.3 +======================================= + +pytest 3.2.3 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 +* Evan +* Joe Hamman +* Oliver Bestwalter +* Ronny Pfannschmidt +* Xuan Luong + + +Happy testing, +The pytest Development Team diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index 6215cf133..ef9161546 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -198,7 +198,6 @@ list:: SKIP [1] test_strings.py:2: got empty parameter set ['stringinput'], function test_valid_string at $REGENDOC_TMPDIR/test_strings.py:1 1 skipped in 0.12 seconds - Note that when calling ``metafunc.parametrize`` multiple times with different parameter sets, all parameter names across those sets cannot be duplicated, otherwise an error will be raised. diff --git a/doc/en/skipping.rst b/doc/en/skipping.rst index 630f73422..1504c251c 100644 --- a/doc/en/skipping.rst +++ b/doc/en/skipping.rst @@ -311,12 +311,12 @@ Running it with the report-on-xfail option gives this output:: platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y rootdir: $REGENDOC_TMPDIR/example, inifile: collected 7 items - + xfail_demo.py xxxxxxx ======= short test summary info ======== XFAIL xfail_demo.py::test_hello XFAIL xfail_demo.py::test_hello2 - reason: [NOTRUN] + reason: [NOTRUN] XFAIL xfail_demo.py::test_hello3 condition: hasattr(os, 'sep') XFAIL xfail_demo.py::test_hello4 @@ -326,7 +326,7 @@ Running it with the report-on-xfail option gives this output:: XFAIL xfail_demo.py::test_hello6 reason: reason XFAIL xfail_demo.py::test_hello7 - + ======= 7 xfailed in 0.12 seconds ======== .. _`skip/xfail with parametrize`: