Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into features #5921

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2fcf21a
Fix logging doc: change x.level to x.levelno
jamescooke Sep 20, 2019
1b4ad77
Fix logging doc: change x.level to x.levelno (#5866)
nicoddemus Sep 21, 2019
de8fdab
Change report-coverage.sh in attempt to fix Azure
nicoddemus Sep 21, 2019
ea0c7e4
Remove unneeded codecov options (implied with "-f")
blueyed Sep 23, 2019
04c01fb
test_argcomplete do not call python directly #5872
Sep 23, 2019
018edf2
Change report-coverage.sh in attempt to fix Azure (#5869)
nicoddemus Sep 23, 2019
d3d9f9f
Merge remote-tracking branch 'upstream/master' into mm
nicoddemus Sep 23, 2019
7c64d5d
Do not call python directly but use sys.executable. Fixes #5872 (#5873)
nicoddemus Sep 23, 2019
c28b631
Merge master into features (#5874)
nicoddemus Sep 23, 2019
19c9e53
Make sure to quote `sys.executable` as we're running a shell
asottile Sep 23, 2019
8806b1f
Merge pull request #5875 from asottile/patch-1
asottile Sep 23, 2019
7731e45
ci: codecov: use 6 retries with curl
blueyed Sep 23, 2019
6bfd30d
Merge pull request #5878 from blueyed/codecov-retry-6
blueyed Sep 24, 2019
7bdfba3
Fix --setup-only and --setup-show for custom pytest items
nicoddemus Sep 28, 2019
b622768
Merge pull request #5886 from nicoddemus/setup-plan-custom-items-5884
asottile Sep 29, 2019
065773a
Use 'python3' instead of 'python3.6' on tox
nicoddemus Sep 28, 2019
068ef90
Preparing release version 5.2.0
nicoddemus Sep 29, 2019
07792c7
Fix attribute docs in _pytest.pytester
asottile Sep 29, 2019
4d01740
Merge pull request #5887 from asottile/fix_attributes_docs_pytester
The-Compiler Sep 29, 2019
88434f1
Release 5.2.0 (#5885)
nicoddemus Sep 29, 2019
acfd0fd
Update doc: pytest section in setup.cfg
tadashigaki Sep 30, 2019
b490f5f
Fix doc typo
kevinjfoley Oct 1, 2019
9a4c0b9
Update doc: pytest section in setup.cfg (#5894)
nicoddemus Oct 1, 2019
a79acf2
Fix warnings with attrs 19.2 and fix object assertions
hynek Oct 1, 2019
33c3ec6
Merge pull request #5898 from kevinjfoley/doc-typo-fix
asottile Oct 1, 2019
9637b3e
Fix dynamic scoping changelog link
asottile Oct 3, 2019
4011af6
Merge pull request #5910 from pytest-dev/asottile-patch-1
asottile Oct 3, 2019
c58b0fb
Use ATTRS_EQ_FIELD for attrs 19.2 compat
asottile Oct 6, 2019
8c9ea5e
Fix warnings with attrs 19.2 and fix object assertions (#5902)
nicoddemus Oct 6, 2019
30ccb31
Merge master into features
blueyed Oct 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ with advance notice in the **Deprecations** section of releases.

.. towncrier release notes start

pytest 5.2.0 (2019-09-28)
=========================

Deprecations
------------

- `#1682 <https://github.com/pytest-dev/pytest/issues/1682>`_: Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them
as a keyword argument instead.



Features
--------

- `#1682 <https://github.com/pytest-dev/pytest/issues/1682>`_: The ``scope`` parameter of ``@pytest.fixture`` can now be a callable that receives
the fixture name and the ``config`` object as keyword-only parameters.
See `the docs <https://docs.pytest.org/en/latest/fixture.html#dynamic-scope>`__ for more information.


- `#5764 <https://github.com/pytest-dev/pytest/issues/5764>`_: New behavior of the ``--pastebin`` option: failures to connect to the pastebin server are reported, without failing the pytest run



Bug Fixes
---------

- `#5806 <https://github.com/pytest-dev/pytest/issues/5806>`_: Fix "lexer" being used when uploading to bpaste.net from ``--pastebin`` to "text".


- `#5884 <https://github.com/pytest-dev/pytest/issues/5884>`_: Fix ``--setup-only`` and ``--setup-show`` for custom pytest items.



Trivial/Internal Changes
------------------------

- `#5056 <https://github.com/pytest-dev/pytest/issues/5056>`_: The HelpFormatter uses ``py.io.get_terminal_width`` for better width detection.


pytest 5.1.3 (2019-09-18)
=========================

Expand Down
2 changes: 0 additions & 2 deletions changelog/1682.deprecation.rst

This file was deleted.

3 changes: 0 additions & 3 deletions changelog/1682.feature.rst

This file was deleted.

1 change: 0 additions & 1 deletion changelog/5056.trivial.rst

This file was deleted.

1 change: 0 additions & 1 deletion changelog/5764.feature.rst

This file was deleted.

1 change: 0 additions & 1 deletion changelog/5806.bugfix.rst

This file was deleted.

1 change: 1 addition & 0 deletions doc/en/announce/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release announcements
:maxdepth: 2


release-5.2.0
release-5.1.3
release-5.1.2
release-5.1.1
Expand Down
36 changes: 36 additions & 0 deletions doc/en/announce/release-5.2.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pytest-5.2.0
=======================================

The pytest team is proud to announce the 5.2.0 release!

pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.

This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:

https://docs.pytest.org/en/latest/changelog.html

For complete documentation, please visit:

https://docs.pytest.org/en/latest/

As usual, you can upgrade from pypi via:

pip install -U pytest

Thanks to all who contributed to this release, among them:

* Andrzej Klajnert
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* James Cooke
* Michael Goerz
* Ran Benita
* Tomáš Chvátal
* aklajnert


Happy testing,
The Pytest Development Team
5 changes: 4 additions & 1 deletion doc/en/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ progress output, you can write it into a configuration file:
.. code-block:: ini

# content of pytest.ini or tox.ini
# setup.cfg files should use [tool:pytest] section instead
[pytest]
addopts = -ra -q

# content of setup.cfg
[tool:pytest]
addopts = -ra -q

Alternatively, you can set a ``PYTEST_ADDOPTS`` environment variable to add command
line options while the environment is in use:

Expand Down
4 changes: 2 additions & 2 deletions doc/en/example/parametrize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@ Running it results in some skips if we don't have all the python interpreters in
.. code-block:: pytest

. $ pytest -rs -q multipython.py
ssssssssssss...ssssssssssss [100%]
ssssssssssssssssssssssss... [100%]
========================= short test summary info ==========================
SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.5' not found
SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.7' not found
SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.6' not found
3 passed, 24 skipped in 0.12s

Indirect parametrization of optional implementations/imports
Expand Down
4 changes: 2 additions & 2 deletions doc/en/example/reportingdemo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
items = [1, 2, 3]
print("items is {!r}".format(items))
> a, b = items.pop()
E TypeError: 'int' object is not iterable
E TypeError: cannot unpack non-iterable int object

failure_demo.py:181: TypeError
--------------------------- Captured stdout call ---------------------------
Expand Down Expand Up @@ -516,7 +516,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
def test_z2_type_error(self):
items = 3
> a, b = items
E TypeError: 'int' object is not iterable
E TypeError: cannot unpack non-iterable int object

failure_demo.py:222: TypeError
______________________ TestMoreErrors.test_startswith ______________________
Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Now we can profile which test functions execute the slowest:

========================= slowest 3 test durations =========================
0.30s call test_some_are_slow.py::test_funcslow2
0.21s call test_some_are_slow.py::test_funcslow1
0.20s call test_some_are_slow.py::test_funcslow1
0.10s call test_some_are_slow.py::test_funcfast
============================ 3 passed in 0.12s =============================

Expand Down
2 changes: 1 addition & 1 deletion doc/en/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Install ``pytest``
.. code-block:: bash

$ pytest --version
This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest.py
This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.7/site-packages/pytest.py

.. _`simpletest`:

Expand Down
2 changes: 1 addition & 1 deletion doc/en/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ the records for the ``setup`` and ``call`` stages during teardown like so:
yield window
for when in ("setup", "call"):
messages = [
x.message for x in caplog.get_records(when) if x.level == logging.WARNING
x.message for x in caplog.get_records(when) if x.levelno == logging.WARNING
]
if messages:
pytest.fail(
Expand Down
2 changes: 1 addition & 1 deletion doc/en/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ passed multiple times. The expected format is ``name=value``. For example::
[pytest]
addopts = --maxfail=2 -rf # exit after 2 failures, report fail info

issuing ``pytest test_hello.py`` actually means::
issuing ``pytest test_hello.py`` actually means:

.. code-block:: bash

Expand Down
3 changes: 2 additions & 1 deletion scripts/report-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ fi
python -m coverage combine
python -m coverage xml
python -m coverage report -m
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X coveragepy -X search -X xcode -X gcovout -X fix -f coverage.xml
curl -S -L --retry 6 -s https://codecov.io/bash -o codecov-upload.sh
bash codecov-upload.sh -Z -X fix -f coverage.xml
5 changes: 4 additions & 1 deletion src/_pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import _pytest._code
from _pytest import outcomes
from _pytest._io.saferepr import saferepr
from _pytest.compat import ATTRS_EQ_FIELD

# The _reprcompare attribute on the util module is used by the new assertion
# interpretation code and assertion rewriter to detect this plugin was
Expand Down Expand Up @@ -375,7 +376,9 @@ def _compare_eq_cls(left, right, verbose, type_fns):
fields_to_check = [field for field, info in all_fields.items() if info.compare]
elif isattrs(left):
all_fields = left.__attrs_attrs__
fields_to_check = [field.name for field in all_fields if field.cmp]
fields_to_check = [
field.name for field in all_fields if getattr(field, ATTRS_EQ_FIELD)
]

same = []
diff = []
Expand Down
6 changes: 6 additions & 0 deletions src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,9 @@ def funcargnames(self):

def overload(f): # noqa: F811
return f


if getattr(attr, "__version_info__", ()) >= (19, 2):
ATTRS_EQ_FIELD = "eq"
else:
ATTRS_EQ_FIELD = "cmp"
4 changes: 3 additions & 1 deletion src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import attr

from ..compat import ascii_escaped
from ..compat import ATTRS_EQ_FIELD
from ..compat import getfslineno
from ..compat import NOTSET
from _pytest.outcomes import fail
Expand Down Expand Up @@ -367,7 +368,8 @@ def __repr__(self):
return "<NodeKeywords for node {}>".format(self.node)


@attr.s(cmp=False, hash=False)
# mypy cannot find this overload, remove when on attrs>=19.2
@attr.s(hash=False, **{ATTRS_EQ_FIELD: False}) # type: ignore
class NodeMarkers:
"""
internal structure for storing marks belonging to a node
Expand Down
17 changes: 8 additions & 9 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,14 @@ class RunResult:

Attributes:

:ret: the return value
:outlines: list of lines captured from stdout
:errlines: list of lines captures from stderr
:stdout: :py:class:`LineMatcher` of stdout, use ``stdout.str()`` to
:ivar ret: the return value
:ivar outlines: list of lines captured from stdout
:ivar errlines: list of lines captured from stderr
:ivar stdout: :py:class:`LineMatcher` of stdout, use ``stdout.str()`` to
reconstruct stdout or the commonly used ``stdout.fnmatch_lines()``
method
:stderr: :py:class:`LineMatcher` of stderr
:duration: duration in seconds

:ivar stderr: :py:class:`LineMatcher` of stderr
:ivar duration: duration in seconds
"""

def __init__(self, ret, outlines, errlines, duration):
Expand Down Expand Up @@ -454,9 +453,9 @@ class Testdir:

Attributes:

:tmpdir: The :py:class:`py.path.local` instance of the temporary directory.
:ivar tmpdir: The :py:class:`py.path.local` instance of the temporary directory.

:plugins: A list of plugins to use with :py:meth:`parseconfig` and
:ivar plugins: A list of plugins to use with :py:meth:`parseconfig` and
:py:meth:`runpytest`. Initially this is an empty list but plugins can
be added to the list. The type of items to add to the list depends on
the method using them so refer to them for details.
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def show_test_item(item):
tw = item.config.get_terminal_writer()
tw.line()
tw.write(" " * 8)
tw.write(item._nodeid)
used_fixtures = sorted(item._fixtureinfo.name2fixturedefs.keys())
tw.write(item.nodeid)
used_fixtures = sorted(getattr(item, "fixturenames", []))
if used_fixtures:
tw.write(" (fixtures used: {})".format(", ".join(used_fixtures)))

Expand Down
27 changes: 27 additions & 0 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,30 @@ def get_write_msg(self, idx):
fullwidth = 80

return TWMock()


@pytest.fixture
def dummy_yaml_custom_test(testdir):
"""Writes a conftest file that collects and executes a dummy yaml test.

Taken from the docs, but stripped down to the bare minimum, useful for
tests which needs custom items collected.
"""
testdir.makeconftest(
"""
import pytest

def pytest_collect_file(parent, path):
if path.ext == ".yaml" and path.basename.startswith("test"):
return YamlFile(path, parent)

class YamlFile(pytest.File):
def collect(self):
yield YamlItem(self.fspath.basename, self)

class YamlItem(pytest.Item):
def runtest(self):
pass
"""
)
testdir.makefile(".yaml", test1="")
6 changes: 3 additions & 3 deletions testing/python/setup_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def mode(request):
return request.param


def test_show_only_active_fixtures(testdir, mode):
p = testdir.makepyfile(
def test_show_only_active_fixtures(testdir, mode, dummy_yaml_custom_test):
testdir.makepyfile(
'''
import pytest
@pytest.fixture
Expand All @@ -21,7 +21,7 @@ def test_arg1(arg1):
'''
)

result = testdir.runpytest(mode, p)
result = testdir.runpytest(mode)
assert result.ret == 0

result.stdout.fnmatch_lines(
Expand Down
6 changes: 3 additions & 3 deletions testing/python/setup_plan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def test_show_fixtures_and_test(testdir):
def test_show_fixtures_and_test(testdir, dummy_yaml_custom_test):
""" Verifies that fixtures are not executed. """
p = testdir.makepyfile(
testdir.makepyfile(
"""
import pytest
@pytest.fixture
Expand All @@ -11,7 +11,7 @@ def test_arg(arg):
"""
)

result = testdir.runpytest("--setup-plan", p)
result = testdir.runpytest("--setup-plan")
assert result.ret == 0

result.stdout.fnmatch_lines(
Expand Down
3 changes: 2 additions & 1 deletion testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from _pytest import outcomes
from _pytest.assertion import truncate
from _pytest.assertion import util
from _pytest.compat import ATTRS_EQ_FIELD


def mock_config():
Expand Down Expand Up @@ -687,7 +688,7 @@ def test_attrs_with_attribute_comparison_off(self):
@attr.s
class SimpleDataObject:
field_a = attr.ib()
field_b = attr.ib(cmp=False)
field_b = attr.ib(**{ATTRS_EQ_FIELD: False})

left = SimpleDataObject(1, "b")
right = SimpleDataObject(1, "b")
Expand Down
7 changes: 6 additions & 1 deletion testing/test_parseopt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import distutils.spawn
import os
import shlex
import sys

import py
Expand Down Expand Up @@ -298,7 +299,11 @@ def test_argcomplete(testdir, monkeypatch):
# redirect output from argcomplete to stdin and stderr is not trivial
# http://stackoverflow.com/q/12589419/1307905
# so we use bash
fp.write('COMP_WORDBREAKS="$COMP_WORDBREAKS" python -m pytest 8>&1 9>&2')
fp.write(
'COMP_WORDBREAKS="$COMP_WORDBREAKS" {} -m pytest 8>&1 9>&2'.format(
shlex.quote(sys.executable)
)
)
# alternative would be exteneded Testdir.{run(),_run(),popen()} to be able
# to handle a keyword argument env that replaces os.environ in popen or
# extends the copy, advantage: could not forget to restore
Expand Down
Loading