Merge branch 'main' of https://github.com/pytest-dev/pytest into downstream_testing_2

This commit is contained in:
sommersoft 2022-04-24 18:27:54 -05:00
commit 841c8c8224
27 changed files with 420 additions and 199 deletions

View File

@ -10,7 +10,7 @@ repos:
- id: blacken-docs - id: blacken-docs
additional_dependencies: [black==20.8b1] additional_dependencies: [black==20.8b1]
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0 rev: v4.2.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
@ -42,12 +42,12 @@ repos:
- id: reorder-python-imports - id: reorder-python-imports
args: ['--application-directories=.:src', --py37-plus] args: ['--application-directories=.:src', --py37-plus]
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v2.31.1 rev: v2.32.0
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py37-plus] args: [--py37-plus]
- repo: https://github.com/asottile/setup-cfg-fmt - repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.0 rev: v1.20.1
hooks: hooks:
- id: setup-cfg-fmt - id: setup-cfg-fmt
args: [--max-py-version=3.10] args: [--max-py-version=3.10]

View File

@ -256,6 +256,7 @@ Ondřej Súkup
Oscar Benjamin Oscar Benjamin
Parth Patel Parth Patel
Patrick Hayes Patrick Hayes
Paul Müller
Pauli Virtanen Pauli Virtanen
Pavel Karateev Pavel Karateev
Paweł Adamczak Paweł Adamczak
@ -325,6 +326,7 @@ Thomas Grainger
Thomas Hisch Thomas Hisch
Tim Hoffmann Tim Hoffmann
Tim Strazny Tim Strazny
Tobias Diez
Tom Dalton Tom Dalton
Tom Viner Tom Viner
Tomáš Gavenčiak Tomáš Gavenčiak

View File

@ -50,6 +50,8 @@ Fix bugs
-------- --------
Look through the `GitHub issues for bugs <https://github.com/pytest-dev/pytest/labels/type:%20bug>`_. Look through the `GitHub issues for bugs <https://github.com/pytest-dev/pytest/labels/type:%20bug>`_.
See also the `"status: easy" issues <https://github.com/pytest-dev/pytest/labels/status%3A%20easy>`_
that are friendly to new contributors.
:ref:`Talk <contact>` to developers to find out how you can fix specific bugs. To indicate that you are going :ref:`Talk <contact>` to developers to find out how you can fix specific bugs. To indicate that you are going
to work on a particular issue, add a comment to that effect on the specific issue. to work on a particular issue, add a comment to that effect on the specific issue.

View File

@ -1 +0,0 @@
An unnecessary ``numpy`` import inside :func:`pytest.approx` was removed.

View File

@ -0,0 +1,3 @@
On Python 3.11, use the standard library's :mod:`tomllib` to parse TOML.
:mod:`tomli`` is no longer a dependency on Python 3.11.

View File

@ -0,0 +1 @@
Improved error message that is shown when no collector is found for a given file.

View File

@ -6,6 +6,7 @@ Release announcements
:maxdepth: 2 :maxdepth: 2
release-7.1.2
release-7.1.1 release-7.1.1
release-7.1.0 release-7.1.0
release-7.0.1 release-7.0.1

View File

@ -0,0 +1,23 @@
pytest-7.1.2
=======================================
pytest 7.1.2 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/stable/changelog.html.
Thanks to all of the contributors to this release:
* Anthony Sottile
* Bruno Oliveira
* Hugo van Kemenade
* Kian Eliasi
* Ran Benita
* Zac Hatfield-Dodds
Happy testing,
The pytest Development Team

View File

@ -170,10 +170,10 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
See https://docs.python.org/library/how-to/capture-warnings.html for information See https://docs.python.org/library/how-to/capture-warnings.html for information
on warning categories. on warning categories.
tmp_path_factory [session scope] -- .../_pytest/tmpdir.py:183 tmp_path_factory [session scope] -- .../_pytest/tmpdir.py:184
Return a :class:`pytest.TempPathFactory` instance for the test session. Return a :class:`pytest.TempPathFactory` instance for the test session.
tmp_path -- .../_pytest/tmpdir.py:198 tmp_path -- .../_pytest/tmpdir.py:199
Return a temporary directory path object which is unique to each test Return a temporary directory path object which is unique to each test
function invocation, created as a sub directory of the base temporary function invocation, created as a sub directory of the base temporary
directory. directory.

View File

@ -28,6 +28,26 @@ with advance notice in the **Deprecations** section of releases.
.. towncrier release notes start .. towncrier release notes start
pytest 7.1.2 (2022-04-23)
=========================
Bug Fixes
---------
- `#9726 <https://github.com/pytest-dev/pytest/issues/9726>`_: An unnecessary ``numpy`` import inside :func:`pytest.approx` was removed.
- `#9820 <https://github.com/pytest-dev/pytest/issues/9820>`_: Fix comparison of ``dataclasses`` with ``InitVar``.
- `#9869 <https://github.com/pytest-dev/pytest/issues/9869>`_: Increase ``stacklevel`` for the ``NODE_CTOR_FSPATH_ARG`` deprecation to point to the
user's code, not pytest.
- `#9871 <https://github.com/pytest-dev/pytest/issues/9871>`_: Fix a bizarre (and fortunately rare) bug where the `temp_path` fixture could raise
an internal error while attempting to get the current user's username.
pytest 7.1.1 (2022-03-17) pytest 7.1.1 (2022-03-17)
========================= =========================

View File

@ -196,7 +196,7 @@ want to distribute them along with your application:
__init__.py __init__.py
app.py app.py
view.py view.py
test/ tests/
__init__.py __init__.py
test_app.py test_app.py
test_view.py test_view.py

View File

@ -22,7 +22,7 @@ Install ``pytest``
.. code-block:: bash .. code-block:: bash
$ pytest --version $ pytest --version
pytest 7.1.1 pytest 7.1.2
.. _`simpletest`: .. _`simpletest`:

View File

@ -198,6 +198,8 @@ option names are:
If you need to record the whole test suite logging calls to a file, you can pass If you need to record the whole test suite logging calls to a file, you can pass
``--log-file=/path/to/log/file``. This log file is opened in write mode which ``--log-file=/path/to/log/file``. This log file is opened in write mode which
means that it will be overwritten at each run tests session. means that it will be overwritten at each run tests session.
Note that relative paths for the log-file location, whether passed on the CLI or declared in a
config file, are always resolved relative to the current working directory.
You can also specify the logging level for the log file by passing You can also specify the logging level for the log file by passing
``--log-file-level``. This setting accepts the logging level names as seen in ``--log-file-level``. This setting accepts the logging level names as seen in

File diff suppressed because it is too large Load Diff

View File

@ -1514,7 +1514,7 @@ passed multiple times. The expected format is ``name=value``. For example::
Sets a file name relative to the ``pytest.ini`` file where log messages should be written to, in addition Sets a file name relative to the current working directory where log messages should be written to, in addition
to the other logging facilities that are active. to the other logging facilities that are active.
.. code-block:: ini .. code-block:: ini

View File

@ -5,3 +5,6 @@ sphinx-removed-in>=0.2.0
sphinx>=3.1,<4 sphinx>=3.1,<4
sphinxcontrib-trio sphinxcontrib-trio
sphinxcontrib-svg2pdfconverter sphinxcontrib-svg2pdfconverter
# XXX: sphinx<4 is broken with latest jinja2
jinja2<3.1

View File

@ -46,10 +46,10 @@ install_requires =
packaging packaging
pluggy>=0.12,<2.0 pluggy>=0.12,<2.0
py>=1.8.2 py>=1.8.2
tomli>=1.0.0
atomicwrites>=1.0;sys_platform=="win32" atomicwrites>=1.0;sys_platform=="win32"
colorama;sys_platform=="win32" colorama;sys_platform=="win32"
importlib-metadata>=0.12;python_version<"3.8" importlib-metadata>=0.12;python_version<"3.8"
tomli>=1.0.0;python_version<"3.11"
python_requires = >=3.7 python_requires = >=3.7
package_dir = package_dir =
=src =src

View File

@ -437,8 +437,10 @@ def _compare_eq_cls(left: Any, right: Any, verbose: int) -> List[str]:
if not has_default_eq(left): if not has_default_eq(left):
return [] return []
if isdatacls(left): if isdatacls(left):
all_fields = left.__dataclass_fields__ import dataclasses
fields_to_check = [field for field, info in all_fields.items() if info.compare]
all_fields = dataclasses.fields(left)
fields_to_check = [info.name for info in all_fields if info.compare]
elif isattrs(left): elif isattrs(left):
all_fields = left.__attrs_attrs__ all_fields = left.__attrs_attrs__
fields_to_check = [field.name for field in all_fields if getattr(field, "eq")] fields_to_check = [field.name for field in all_fields if getattr(field, "eq")]

View File

@ -1,4 +1,5 @@
import os import os
import sys
from pathlib import Path from pathlib import Path
from typing import Dict from typing import Dict
from typing import Iterable from typing import Iterable
@ -64,12 +65,15 @@ def load_config_dict_from_file(
# '.toml' files are considered if they contain a [tool.pytest.ini_options] table. # '.toml' files are considered if they contain a [tool.pytest.ini_options] table.
elif filepath.suffix == ".toml": elif filepath.suffix == ".toml":
import tomli if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
toml_text = filepath.read_text(encoding="utf-8") toml_text = filepath.read_text(encoding="utf-8")
try: try:
config = tomli.loads(toml_text) config = tomllib.loads(toml_text)
except tomli.TOMLDecodeError as exc: except tomllib.TOMLDecodeError as exc:
raise UsageError(f"{filepath}: {exc}") from exc raise UsageError(f"{filepath}: {exc}") from exc
result = config.get("tool", {}).get("pytest", {}).get("ini_options", None) result = config.get("tool", {}).get("pytest", {}).get("ini_options", None)

View File

@ -645,9 +645,14 @@ class Session(nodes.FSCollector):
self.trace.root.indent -= 1 self.trace.root.indent -= 1
if self._notfound: if self._notfound:
errors = [] errors = []
for arg, cols in self._notfound: for arg, collectors in self._notfound:
line = f"(no name {arg!r} in any of {cols!r})" if collectors:
errors.append(f"not found: {arg}\n{line}") errors.append(
f"not found: {arg}\n(no name {arg!r} in any of {collectors!r})"
)
else:
errors.append(f"found no collectors for {arg}")
raise UsageError(*errors) raise UsageError(*errors)
if not genitems: if not genitems:
items = rep.result items = rep.result

View File

@ -111,7 +111,7 @@ def _imply_path(
NODE_CTOR_FSPATH_ARG.format( NODE_CTOR_FSPATH_ARG.format(
node_type_name=node_type.__name__, node_type_name=node_type.__name__,
), ),
stacklevel=3, stacklevel=6,
) )
if path is not None: if path is not None:
if fspath is not None: if fspath is not None:

View File

@ -158,9 +158,10 @@ class TempPathFactory:
def get_user() -> Optional[str]: def get_user() -> Optional[str]:
"""Return the current user name, or None if getuser() does not work """Return the current user name, or None if getuser() does not work
in the current environment (see #1010).""" in the current environment (see #1010)."""
try:
# In some exotic environments, getpass may not be importable.
import getpass import getpass
try:
return getpass.getuser() return getpass.getuser()
except (ImportError, KeyError): except (ImportError, KeyError):
return None return None

View File

@ -186,8 +186,7 @@ class TestGeneralUsage:
assert result.ret == ExitCode.USAGE_ERROR assert result.ret == ExitCode.USAGE_ERROR
result.stderr.fnmatch_lines( result.stderr.fnmatch_lines(
[ [
f"ERROR: not found: {p2}", f"ERROR: found no collectors for {p2}",
f"(no name {str(p2)!r} in any of [[][]])",
"", "",
] ]
) )

View File

@ -0,0 +1,12 @@
from dataclasses import dataclass
from dataclasses import InitVar
@dataclass
class Foo:
init_only: InitVar[int]
real_attr: int
def test_demonstrate():
assert Foo(1, 2) == Foo(1, 3)

View File

@ -1,6 +1,6 @@
anyio[curio,trio]==3.5.0 anyio[curio,trio]==3.5.0
django==4.0.3 django==4.0.4
pytest-asyncio==0.18.2 pytest-asyncio==0.18.3
pytest-bdd==5.0.0 pytest-bdd==5.0.0
pytest-cov==3.0.0 pytest-cov==3.0.0
pytest-django==4.5.2 pytest-django==4.5.2
@ -11,5 +11,5 @@ pytest-rerunfailures==10.2
pytest-sugar==0.9.4 pytest-sugar==0.9.4
pytest-trio==0.7.0 pytest-trio==0.7.0
pytest-twisted==1.13.4 pytest-twisted==1.13.4
twisted==22.2.0 twisted==22.4.0
pytest-xvfb==2.0.0 pytest-xvfb==2.0.0

View File

@ -882,6 +882,13 @@ class TestAssert_reprcompare_dataclass:
result.assert_outcomes(failed=1, passed=0) result.assert_outcomes(failed=1, passed=0)
result.stdout.no_re_match_line(".*Differing attributes.*") result.stdout.no_re_match_line(".*Differing attributes.*")
def test_data_classes_with_initvar(self, pytester: Pytester) -> None:
p = pytester.copy_example("dataclasses/test_compare_initvar.py")
# issue 9820
result = pytester.runpytest(p, "-vv")
result.assert_outcomes(failed=1, passed=0)
result.stdout.no_re_match_line(".*AttributeError.*")
class TestAssert_reprcompare_attrsclass: class TestAssert_reprcompare_attrsclass:
def test_attrs(self) -> None: def test_attrs(self) -> None:

View File

@ -1855,8 +1855,7 @@ def test_config_blocked_default_plugins(pytester: Pytester, plugin: str) -> None
assert result.ret == ExitCode.USAGE_ERROR assert result.ret == ExitCode.USAGE_ERROR
result.stderr.fnmatch_lines( result.stderr.fnmatch_lines(
[ [
"ERROR: not found: */test_config_blocked_default_plugins.py", "ERROR: found no collectors for */test_config_blocked_default_plugins.py",
"(no name '*/test_config_blocked_default_plugins.py' in any of [])",
] ]
) )
return return