From 71b79fcda5313624544ae501a2045186c1c72244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gergely=20Kalm=C3=A1r?= Date: Fri, 26 Aug 2022 14:46:47 +0200 Subject: [PATCH 1/2] [7.1.x] Ignore editable installation modules --- changelog/10230.bugfix.rst | 1 + src/_pytest/config/__init__.py | 3 ++- testing/test_config.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelog/10230.bugfix.rst diff --git a/changelog/10230.bugfix.rst b/changelog/10230.bugfix.rst new file mode 100644 index 00000000000..6ca2b00bf89 --- /dev/null +++ b/changelog/10230.bugfix.rst @@ -0,0 +1 @@ +Ignore ``.py`` files created by ``pyproject.toml``-based editable builds introduced in `pip 21.3 `__. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 91ad3f094ff..53f40c24571 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -833,7 +833,8 @@ def _iter_rewritable_modules(package_files: Iterable[str]) -> Iterator[str]: if is_simple_module: module_name, _ = os.path.splitext(fn) # we ignore "setup.py" at the root of the distribution - if module_name != "setup": + # as well as editable installation finder modules made by setuptools + if module_name != "setup" and not module_name.startswith("__editable__"): seen_some = True yield module_name elif is_package: diff --git a/testing/test_config.py b/testing/test_config.py index 6784809e097..3653ce47fa3 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -837,6 +837,9 @@ def test_confcutdir_check_isdir(self, pytester: Pytester) -> None: (["src/bar/__init__.py"], ["bar"]), (["src/bar/__init__.py", "setup.py"], ["bar"]), (["source/python/bar/__init__.py", "setup.py"], ["bar"]), + # editable installation finder modules + (["__editable___xyz_finder.py"], []), + (["bar/__init__.py", "__editable___xyz_finder.py"], ["bar"]), ], ) def test_iter_rewritable_modules(self, names, expected) -> None: From aae93d6127c43a7f9036556ba7482019d389e21d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 26 Aug 2022 09:57:18 -0300 Subject: [PATCH 2/2] Ignore type-errors related to attr.asdict --- src/_pytest/reports.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 725fdf61739..3c58321e706 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -455,7 +455,7 @@ def _report_to_json(report: BaseReport) -> Dict[str, Any]: def serialize_repr_entry( entry: Union[ReprEntry, ReprEntryNative] ) -> Dict[str, Any]: - data = attr.asdict(entry) + data = attr.asdict(entry) # type:ignore[arg-type] for key, value in data.items(): if hasattr(value, "__dict__"): data[key] = attr.asdict(value) @@ -463,7 +463,7 @@ def serialize_repr_entry( return entry_data def serialize_repr_traceback(reprtraceback: ReprTraceback) -> Dict[str, Any]: - result = attr.asdict(reprtraceback) + result = attr.asdict(reprtraceback) # type:ignore[arg-type] result["reprentries"] = [ serialize_repr_entry(x) for x in reprtraceback.reprentries ] @@ -473,7 +473,7 @@ def serialize_repr_crash( reprcrash: Optional[ReprFileLocation], ) -> Optional[Dict[str, Any]]: if reprcrash is not None: - return attr.asdict(reprcrash) + return attr.asdict(reprcrash) # type:ignore[arg-type] else: return None