From 50764d9ebbea4cd15717e49ba4ef4f467254a2be Mon Sep 17 00:00:00 2001 From: Andras Tim Date: Fri, 21 Jul 2017 21:27:48 +0200 Subject: [PATCH 1/7] Avoid interactive pdb when pytest tests itself - fix #2023 The debugging.py calls post_mortem() on error and pdb will drops an interactive debugger when the stdin is a readable fd. --- _pytest/pytester.py | 7 +++++-- changelog/2023.bugfix | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog/2023.bugfix diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 1783c9c0c..674adca94 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -916,8 +916,11 @@ class Testdir: env['PYTHONPATH'] = os.pathsep.join(filter(None, [ str(os.getcwd()), env.get('PYTHONPATH', '')])) kw['env'] = env - return subprocess.Popen(cmdargs, - stdout=stdout, stderr=stderr, **kw) + + popen = subprocess.Popen(cmdargs, stdin=subprocess.PIPE, stdout=stdout, stderr=stderr, **kw) + popen.stdin.close() + + return popen def run(self, *cmdargs): """Run a command with arguments. diff --git a/changelog/2023.bugfix b/changelog/2023.bugfix new file mode 100644 index 000000000..acf4b405b --- /dev/null +++ b/changelog/2023.bugfix @@ -0,0 +1 @@ +Set ``stdin`` to a closed ``PIPE`` in ``pytester.py.Testdir.popen()`` for avoid unwanted interactive ``pdb`` From 72531f30c0d8834230f2007fe5b563c9fe5af04b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 4 Jul 2017 12:16:42 +0200 Subject: [PATCH 2/7] Improve error message for CollectError with skip/skipif --- _pytest/python.py | 7 ++++--- changelog/2546.trivial | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelog/2546.trivial diff --git a/_pytest/python.py b/_pytest/python.py index d0f13a758..29e3182d4 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -442,9 +442,10 @@ class Module(main.File, PyCollector): if e.allow_module_level: raise raise self.CollectError( - "Using pytest.skip outside of a test is not allowed. If you are " - "trying to decorate a test function, use the @pytest.mark.skip " - "or @pytest.mark.skipif decorators instead." + "Using pytest.skip outside of a test is not allowed. " + "To decorate a test function, use the @pytest.mark.skip " + "or @pytest.mark.skipif decorators instead, and to skip a " + "module use `pytestmark = pytest.mark.{skip,skipif}." ) self.config.pluginmanager.consider_module(mod) return mod diff --git a/changelog/2546.trivial b/changelog/2546.trivial new file mode 100644 index 000000000..53e43bc17 --- /dev/null +++ b/changelog/2546.trivial @@ -0,0 +1 @@ +Improve error message for CollectError with skip/skipif. From 869eed9898df0d06c7d9be916d4224141c7dd3fe Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 4 Jul 2017 12:57:15 +0200 Subject: [PATCH 3/7] Fix lineno offset in show_skipped The line number is 0-based here, so add 1. --- _pytest/skipping.py | 2 +- changelog/2548.bugfix | 1 + testing/test_skipping.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 changelog/2548.bugfix diff --git a/_pytest/skipping.py b/_pytest/skipping.py index 619650092..b11aea801 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -382,4 +382,4 @@ def show_skipped(terminalreporter, lines): reason = reason[9:] lines.append( "SKIP [%d] %s:%d: %s" % - (num, fspath, lineno, reason)) + (num, fspath, lineno + 1, reason)) diff --git a/changelog/2548.bugfix b/changelog/2548.bugfix new file mode 100644 index 000000000..9a44dc334 --- /dev/null +++ b/changelog/2548.bugfix @@ -0,0 +1 @@ +Fix lineno offset in show_skipped. diff --git a/testing/test_skipping.py b/testing/test_skipping.py index b780e4dc8..6608ccadf 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -708,7 +708,7 @@ def test_skipped_reasons_functional(testdir): ) result = testdir.runpytest('-rs') result.stdout.fnmatch_lines([ - "*SKIP*2*conftest.py:3: test", + "*SKIP*2*conftest.py:4: test", ]) assert result.ret == 0 From 949a1406f08495e0365e5ce91ea14ab104a34866 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 25 Jul 2017 18:27:26 +0200 Subject: [PATCH 4/7] Revisit CONTRIBUTING.rst --- CONTRIBUTING.rst | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b3bdde78b..fa317fd1b 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -34,13 +34,13 @@ If you are reporting a bug, please include: * Your operating system name and version. * Any details about your local setup that might be helpful in troubleshooting, - specifically Python interpreter version, - installed libraries and pytest version. + specifically the Python interpreter version, installed libraries, and pytest + version. * Detailed steps to reproduce the bug. -If you can write a demonstration test that currently fails but should pass (xfail), -that is a very useful commit to make as well, even if you can't find how -to fix the bug yet. +If you can write a demonstration test that currently fails but should pass +(xfail), that is a very useful commit to make as well, even if you cannot +fix the bug itself. .. _fixbugs: @@ -165,29 +165,30 @@ Short version ~~~~~~~~~~~~~ #. Fork the repository; -#. Target ``master`` for bug-fix and doc changes; +#. Target ``master`` for bugfixes and doc changes; #. Target ``features`` for new features or functionality changes. #. Follow **PEP-8**. There's a ``tox`` command to help fixing it: ``tox -e fix-lint``. #. Tests are run using ``tox``:: tox -e linting,py27,py36 - The test environments above are usually enough to to cover most cases locally. + The test environments above are usually enough to cover most cases locally. -#. Write a ``changelog`` entry: ``changelog/2574.bugfix``, use issue id number and one of - ``bugfix``, ``removal``, ``feature``, ``vendor``, ``doc`` or ``trivial`` for the issue type. +#. Write a ``changelog`` entry: ``changelog/2574.bugfix``, use issue id number + and one of ``bugfix``, ``removal``, ``feature``, ``vendor``, ``doc`` or + ``trivial`` for the issue type. #. Add yourself to ``AUTHORS`` file if not there yet, in alphabetical order. Long version ~~~~~~~~~~~~ - -What is a "pull request"? It informs project's core developers about the +What is a "pull request"? It informs the project's core developers about the changes you want to review and merge. Pull requests are stored on `GitHub servers `_. Once you send a pull request, we can discuss its potential modifications and -even add more commits to it later on. There's an excellent tutorial on how Pull Requests work in the +even add more commits to it later on. There's an excellent tutorial on how Pull +Requests work in the `GitHub Help Center `_. Here is a simple overview, with pytest-specific bits: From 1a42e2658648dd967dd76958e2da817fd30850d6 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 25 Jul 2017 13:37:06 -0300 Subject: [PATCH 5/7] Improve changelog wording to be more user-oriented --- changelog/2548.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/2548.bugfix b/changelog/2548.bugfix index 9a44dc334..8201594ed 100644 --- a/changelog/2548.bugfix +++ b/changelog/2548.bugfix @@ -1 +1 @@ -Fix lineno offset in show_skipped. +Fix line number when reporting summary of skipped tests. From 0603d1d500c14a67715e486568b50f15b2086616 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 5 Jul 2017 21:54:33 +0200 Subject: [PATCH 6/7] capture: ensure name of EncodedFile being a string Fixes https://github.com/pytest-dev/pytest/issues/2555. --- _pytest/capture.py | 5 +++++ changelog/2555.bugfix | 1 + testing/test_capture.py | 10 ++++++++++ 3 files changed, 16 insertions(+) create mode 100644 changelog/2555.bugfix diff --git a/_pytest/capture.py b/_pytest/capture.py index b627e5102..a4171f0fa 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -254,6 +254,11 @@ class EncodedFile(object): data = ''.join(linelist) self.write(data) + @property + def name(self): + """Ensure that file.name is a string.""" + return repr(self.buffer) + def __getattr__(self, name): return getattr(object.__getattribute__(self, "buffer"), name) diff --git a/changelog/2555.bugfix b/changelog/2555.bugfix new file mode 100644 index 000000000..8c20bbc67 --- /dev/null +++ b/changelog/2555.bugfix @@ -0,0 +1 @@ +capture: ensure that EncodedFile.name is a string. diff --git a/testing/test_capture.py b/testing/test_capture.py index 313819a96..4dd5d8e09 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -716,13 +716,21 @@ def test_dupfile(tmpfile): assert nf not in flist print(i, end="", file=nf) flist.append(nf) + + fname_open = flist[0].name + assert fname_open == repr(flist[0].buffer) + for i in range(5): f = flist[i] f.close() + fname_closed = flist[0].name + assert fname_closed == repr(flist[0].buffer) + assert fname_closed != fname_open tmpfile.seek(0) s = tmpfile.read() assert "01234" in repr(s) tmpfile.close() + assert fname_closed == repr(flist[0].buffer) def test_dupfile_on_bytesio(): @@ -730,6 +738,7 @@ def test_dupfile_on_bytesio(): f = capture.safe_text_dupfile(io, "wb") f.write("hello") assert io.getvalue() == b"hello" + assert 'BytesIO object' in f.name def test_dupfile_on_textio(): @@ -737,6 +746,7 @@ def test_dupfile_on_textio(): f = capture.safe_text_dupfile(io, "wb") f.write("hello") assert io.getvalue() == "hello" + assert not hasattr(f, 'name') @contextlib.contextmanager From 10ded399d8246ef8383d5cac27f58fe9b0c65fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihai=20Capot=C4=83?= Date: Wed, 26 Jul 2017 09:55:42 -0700 Subject: [PATCH 7/7] Show multiple issue links in CHANGELOG entries Restores the functionality removed in PR #2488. --- AUTHORS | 1 + changelog/2620.trivial | 1 + changelog/_template.rst | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog/2620.trivial diff --git a/AUTHORS b/AUTHORS index d58cd3d2d..5259d0322 100644 --- a/AUTHORS +++ b/AUTHORS @@ -120,6 +120,7 @@ Michael Birtwell Michael Droettboom Michael Seifert Michal Wajszczuk +Mihai Capotă Mike Lundy Ned Batchelder Neven Mundar diff --git a/changelog/2620.trivial b/changelog/2620.trivial new file mode 100644 index 000000000..51c0bd160 --- /dev/null +++ b/changelog/2620.trivial @@ -0,0 +1 @@ +Show multiple issue links in CHANGELOG entries. diff --git a/changelog/_template.rst b/changelog/_template.rst index 66c850ffd..a898abc15 100644 --- a/changelog/_template.rst +++ b/changelog/_template.rst @@ -13,7 +13,8 @@ {% if definitions[category]['showcontent'] %} {% for text, values in sections[section][category]|dictsort(by='value') %} -- {{ text }}{% if category != 'vendor' %} (`{{ values[0] }} `_){% endif %} +{% set issue_joiner = joiner(', ') %} +- {{ text }}{% if category != 'vendor' %} ({% for value in values|sort %}{{ issue_joiner() }}`{{ value }} `_{% endfor %}){% endif %} {% endfor %}