Merge remote-tracking branch 'origin/master' into mm

This commit is contained in:
Anthony Sottile 2019-11-15 15:26:57 -08:00
commit cc78444c30
16 changed files with 143 additions and 28 deletions

View File

@ -2,15 +2,14 @@
Thanks for submitting a PR, your contribution is really appreciated! Thanks for submitting a PR, your contribution is really appreciated!
Here is a quick checklist that should be present in PRs. Here is a quick checklist that should be present in PRs.
(please delete this text from the final description, this is just a guideline)
-->
- [ ] Target the `master` branch for bug fixes, documentation updates and trivial changes. - [ ] Target the `master` branch for bug fixes, documentation updates and trivial changes.
- [ ] Target the `features` branch for new features, improvements, and removals/deprecations. - [ ] Target the `features` branch for new features, improvements, and removals/deprecations.
- [ ] Include documentation when adding new features. - [ ] Include documentation when adding new features.
- [ ] Include new tests or update existing tests when applicable. - [ ] Include new tests or update existing tests when applicable.
Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please: 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 `<ISSUE NUMBER>.<TYPE>.rst`. See [changelog/README.rst](https://github.com/pytest-dev/pytest/blob/master/changelog/README.rst) for details. - [ ] Create a new changelog file in the `changelog` folder, with a name like `<ISSUE NUMBER>.<TYPE>.rst`. See [changelog/README.rst](https://github.com/pytest-dev/pytest/blob/master/changelog/README.rst) for details.
- [ ] Add yourself to `AUTHORS` in alphabetical order; - [ ] Add yourself to `AUTHORS` in alphabetical order.
-->

View File

@ -70,6 +70,7 @@ Daniel Hahler
Daniel Nuri Daniel Nuri
Daniel Wandschneider Daniel Wandschneider
Danielle Jenkins Danielle Jenkins
Daniil Galiev
Dave Hunt Dave Hunt
David Díaz-Barquero David Díaz-Barquero
David Mohr David Mohr

View File

@ -18,6 +18,34 @@ with advance notice in the **Deprecations** section of releases.
.. towncrier release notes start .. towncrier release notes start
pytest 5.2.4 (2019-11-15)
=========================
Bug Fixes
---------
- `#6194 <https://github.com/pytest-dev/pytest/issues/6194>`_: Fix incorrect discovery of non-test ``__init__.py`` files.
- `#6197 <https://github.com/pytest-dev/pytest/issues/6197>`_: Revert "The first test in a package (``__init__.py``) marked with ``@pytest.mark.skip`` is now correctly skipped.".
pytest 5.2.3 (2019-11-14)
=========================
Bug Fixes
---------
- `#5830 <https://github.com/pytest-dev/pytest/issues/5830>`_: The first test in a package (``__init__.py``) marked with ``@pytest.mark.skip`` is now correctly skipped.
- `#6099 <https://github.com/pytest-dev/pytest/issues/6099>`_: Fix ``--trace`` when used with parametrized functions.
- `#6183 <https://github.com/pytest-dev/pytest/issues/6183>`_: Using ``request`` as a parameter name in ``@pytest.mark.parametrize`` now produces a more
user-friendly error.
pytest 5.2.2 (2019-10-24) pytest 5.2.2 (2019-10-24)
========================= =========================

View File

@ -1 +0,0 @@
Fix ``--trace`` when used with parametrized functions.

View File

@ -6,6 +6,8 @@ Release announcements
:maxdepth: 2 :maxdepth: 2
release-5.2.4
release-5.2.3
release-5.2.2 release-5.2.2
release-5.2.1 release-5.2.1
release-5.2.0 release-5.2.0

View File

@ -0,0 +1,28 @@
pytest-5.2.3
=======================================
pytest 5.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 https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Brett Cannon
* Bruno Oliveira
* Daniel Hahler
* Daniil Galiev
* David Szotten
* Florian Bruhin
* Patrick Harmon
* Ran Benita
* Zac Hatfield-Dodds
* Zak Hassan
Happy testing,
The pytest Development Team

View File

@ -0,0 +1,22 @@
pytest-5.2.4
=======================================
pytest 5.2.4 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:
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Hugo
* Michael Shields
Happy testing,
The pytest Development Team

View File

@ -475,11 +475,10 @@ Running it results in some skips if we don't have all the python interpreters in
.. code-block:: pytest .. code-block:: pytest
. $ pytest -rs -q multipython.py . $ pytest -rs -q multipython.py
ssssssssssssssssssssssss... [100%] ssssssssssss......sss...... [100%]
========================= short test summary info ========================== ========================= short test summary info ==========================
SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.5' not found SKIPPED [15] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.5' not found
SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.6' not found 12 passed, 15 skipped in 0.12s
3 passed, 24 skipped in 0.12s
Indirect parametrization of optional implementations/imports Indirect parametrization of optional implementations/imports
-------------------------------------------------------------------- --------------------------------------------------------------------

View File

@ -436,7 +436,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
items = [1, 2, 3] items = [1, 2, 3]
print("items is {!r}".format(items)) print("items is {!r}".format(items))
> a, b = items.pop() > a, b = items.pop()
E TypeError: cannot unpack non-iterable int object E TypeError: 'int' object is not iterable
failure_demo.py:181: TypeError failure_demo.py:181: TypeError
--------------------------- Captured stdout call --------------------------- --------------------------- Captured stdout call ---------------------------
@ -516,7 +516,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
def test_z2_type_error(self): def test_z2_type_error(self):
items = 3 items = 3
> a, b = items > a, b = items
E TypeError: cannot unpack non-iterable int object E TypeError: 'int' object is not iterable
failure_demo.py:222: TypeError failure_demo.py:222: TypeError
______________________ TestMoreErrors.test_startswith ______________________ ______________________ TestMoreErrors.test_startswith ______________________

View File

@ -300,36 +300,33 @@ behave differently if called from a test. But if you
absolutely must find out if your application code is absolutely must find out if your application code is
running from a test you can do something like this: running from a test you can do something like this:
.. code-block:: python
# content of your_module.py
_called_from_test = False
.. code-block:: python .. code-block:: python
# content of conftest.py # content of conftest.py
def pytest_configure(config): def pytest_configure(config):
import sys your_module._called_from_test = True
sys._called_from_test = True and then check for the ``your_module._called_from_test`` flag:
def pytest_unconfigure(config):
import sys
del sys._called_from_test
and then check for the ``sys._called_from_test`` flag:
.. code-block:: python .. code-block:: python
if hasattr(sys, "_called_from_test"): if your_module._called_from_test:
# called from within a test run # called from within a test run
... ...
else: else:
# called "normally" # called "normally"
... ...
accordingly in your application. It's also a good idea accordingly in your application.
to use your own application module rather than ``sys``
for handling flag.
Adding info to test report header Adding info to test report header
-------------------------------------------------------------- --------------------------------------------------------------

View File

@ -28,7 +28,7 @@ Install ``pytest``
.. code-block:: bash .. code-block:: bash
$ pytest --version $ pytest --version
This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.7/site-packages/pytest.py This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest.py
.. _`simpletest`: .. _`simpletest`:

View File

@ -59,7 +59,7 @@ pytest.raises
**Tutorial**: :ref:`assertraises`. **Tutorial**: :ref:`assertraises`.
.. autofunction:: pytest.raises(expected_exception: Exception, [match]) .. autofunction:: pytest.raises(expected_exception: Exception [, *, match])
:with: excinfo :with: excinfo
pytest.deprecated_call pytest.deprecated_call

View File

@ -57,7 +57,7 @@ upload-dir = doc/en/build/html
[check-manifest] [check-manifest]
ignore = ignore =
_pytest/_version.py src/_pytest/_version.py
[devpi:upload] [devpi:upload]
formats = sdist.tgz,bdist_wheel formats = sdist.tgz,bdist_wheel

View File

@ -966,6 +966,12 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
) )
del argvalues del argvalues
if "request" in argnames:
fail(
"'request' is a reserved name and cannot be used in @pytest.mark.parametrize",
pytrace=False,
)
if scope is None: if scope is None:
scope = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect) scope = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect)

View File

@ -72,6 +72,19 @@ class TestMetafunc:
): ):
metafunc.parametrize("x", [1], scope="doggy") metafunc.parametrize("x", [1], scope="doggy")
def test_parametrize_request_name(self, testdir):
"""Show proper error when 'request' is used as a parameter name in parametrize (#6183)"""
def func(request):
raise NotImplementedError()
metafunc = self.Metafunc(func)
with pytest.raises(
pytest.fail.Exception,
match=r"'request' is a reserved name and cannot be used in @pytest.mark.parametrize",
):
metafunc.parametrize("request", [1])
def test_find_parametrized_scope(self): def test_find_parametrized_scope(self):
"""unittest for _find_parametrized_scope (#3941)""" """unittest for _find_parametrized_scope (#3941)"""
from _pytest.python import _find_parametrized_scope from _pytest.python import _find_parametrized_scope

View File

@ -1262,3 +1262,24 @@ def test_collector_respects_tbstyle(testdir):
"*= 1 error in *", "*= 1 error in *",
] ]
) )
def test_does_not_eagerly_collect_packages(testdir):
testdir.makepyfile("def test(): pass")
pydir = testdir.mkpydir("foopkg")
pydir.join("__init__.py").write("assert False")
result = testdir.runpytest()
assert result.ret == ExitCode.OK
def test_does_not_put_src_on_path(testdir):
# `src` is not on sys.path so it should not be importable
testdir.tmpdir.join("src/nope/__init__.py").ensure()
testdir.makepyfile(
"import pytest\n"
"def test():\n"
" with pytest.raises(ImportError):\n"
" import nope\n"
)
result = testdir.runpytest()
assert result.ret == ExitCode.OK