Skip to content

Commit

Permalink
Merge branch 'pytest-dev:main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Apr 22, 2022
2 parents 387ec02 + 28e8c85 commit 7df4057
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 153 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
args: [--safe, --quiet]
Expand All @@ -10,7 +10,7 @@ repos:
- id: blacken-docs
additional_dependencies: [black==20.8b1]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down Expand Up @@ -42,12 +42,12 @@ repos:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py37-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v2.32.0
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.0
rev: v1.20.1
hooks:
- id: setup-cfg-fmt
args: [--max-py-version=3.10]
Expand All @@ -56,7 +56,7 @@ repos:
hooks:
- id: python-use-type-annotations
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.941
rev: v0.942
hooks:
- id: mypy
files: ^(src/|testing/)
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -256,6 +256,7 @@ Ondřej Súkup
Oscar Benjamin
Parth Patel
Patrick Hayes
Paul Müller
Pauli Virtanen
Pavel Karateev
Paweł Adamczak
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.rst
Expand Up @@ -50,6 +50,8 @@ Fix bugs
--------

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
to work on a particular issue, add a comment to that effect on the specific issue.
Expand Down
3 changes: 3 additions & 0 deletions changelog/9741.improvement.rst
@@ -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.
1 change: 1 addition & 0 deletions changelog/9820.bugfix.rst
@@ -0,0 +1 @@
Fix comparison of ``dataclasses`` with ``InitVar``.
2 changes: 2 additions & 0 deletions changelog/9869.bugfix.rst
@@ -0,0 +1,2 @@
Increase ``stacklevel`` for the ``NODE_CTOR_FSPATH_ARG`` deprecation to point to the
user's code, not pytest.
2 changes: 2 additions & 0 deletions changelog/9871.bugfix.rst
@@ -0,0 +1,2 @@
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.
2 changes: 1 addition & 1 deletion doc/en/explanation/goodpractices.rst
Expand Up @@ -196,7 +196,7 @@ want to distribute them along with your application:
__init__.py
app.py
view.py
test/
tests/
__init__.py
test_app.py
test_view.py
Expand Down
366 changes: 231 additions & 135 deletions doc/en/reference/plugin_list.rst

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions doc/en/requirements.txt
Expand Up @@ -5,3 +5,6 @@ sphinx-removed-in>=0.2.0
sphinx>=3.1,<4
sphinxcontrib-trio
sphinxcontrib-svg2pdfconverter

# XXX: sphinx<4 is broken with latest jinja2
jinja2<3.1
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -46,10 +46,10 @@ install_requires =
packaging
pluggy>=0.12,<2.0
py>=1.8.2
tomli>=1.0.0
atomicwrites>=1.0;sys_platform=="win32"
colorama;sys_platform=="win32"
importlib-metadata>=0.12;python_version<"3.8"
tomli>=1.0.0;python_version<"3.11"
python_requires = >=3.7
package_dir =
=src
Expand Down
6 changes: 4 additions & 2 deletions src/_pytest/assertion/util.py
Expand Up @@ -437,8 +437,10 @@ def _compare_eq_cls(left: Any, right: Any, verbose: int) -> List[str]:
if not has_default_eq(left):
return []
if isdatacls(left):
all_fields = left.__dataclass_fields__
fields_to_check = [field for field, info in all_fields.items() if info.compare]
import dataclasses

all_fields = dataclasses.fields(left)
fields_to_check = [info.name for info in all_fields if info.compare]
elif isattrs(left):
all_fields = left.__attrs_attrs__
fields_to_check = [field.name for field in all_fields if getattr(field, "eq")]
Expand Down
10 changes: 7 additions & 3 deletions src/_pytest/config/findpaths.py
@@ -1,4 +1,5 @@
import os
import sys
from pathlib import Path
from typing import Dict
from typing import Iterable
Expand Down Expand Up @@ -64,12 +65,15 @@ def load_config_dict_from_file(

# '.toml' files are considered if they contain a [tool.pytest.ini_options] table.
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")
try:
config = tomli.loads(toml_text)
except tomli.TOMLDecodeError as exc:
config = tomllib.loads(toml_text)
except tomllib.TOMLDecodeError as exc:
raise UsageError(f"{filepath}: {exc}") from exc

result = config.get("tool", {}).get("pytest", {}).get("ini_options", None)
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/nodes.py
Expand Up @@ -111,7 +111,7 @@ def _imply_path(
NODE_CTOR_FSPATH_ARG.format(
node_type_name=node_type.__name__,
),
stacklevel=3,
stacklevel=6,
)
if path is not None:
if fspath is not None:
Expand Down
5 changes: 3 additions & 2 deletions src/_pytest/tmpdir.py
Expand Up @@ -158,9 +158,10 @@ def getbasetemp(self) -> Path:
def get_user() -> Optional[str]:
"""Return the current user name, or None if getuser() does not work
in the current environment (see #1010)."""
import getpass

try:
# In some exotic environments, getpass may not be importable.
import getpass

return getpass.getuser()
except (ImportError, KeyError):
return None
Expand Down
12 changes: 12 additions & 0 deletions testing/example_scripts/dataclasses/test_compare_initvar.py
@@ -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)
6 changes: 3 additions & 3 deletions testing/plugins_integration/requirements.txt
@@ -1,6 +1,6 @@
anyio[curio,trio]==3.5.0
django==4.0.3
pytest-asyncio==0.18.2
django==4.0.4
pytest-asyncio==0.18.3
pytest-bdd==5.0.0
pytest-cov==3.0.0
pytest-django==4.5.2
Expand All @@ -11,5 +11,5 @@ pytest-rerunfailures==10.2
pytest-sugar==0.9.4
pytest-trio==0.7.0
pytest-twisted==1.13.4
twisted==22.2.0
twisted==22.4.0
pytest-xvfb==2.0.0
7 changes: 7 additions & 0 deletions testing/test_assertion.py
Expand Up @@ -882,6 +882,13 @@ def test_data_classes_with_custom_eq(self, pytester: Pytester) -> None:
result.assert_outcomes(failed=1, passed=0)
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:
def test_attrs(self) -> None:
Expand Down

0 comments on commit 7df4057

Please sign in to comment.