From b64508a7f8255c963b51ba4832d4a6d2d3c5769f Mon Sep 17 00:00:00 2001 From: Accessac Date: Tue, 2 Apr 2024 11:49:31 +0800 Subject: [PATCH] Add Patch1 0001-Fix-assertion-rewriting-on-Python-3.10-plus.patch --- ...ertion-rewriting-on-Python-3.10-plus.patch | 63 +++++++++++++++++++ pytest.spec | 6 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-assertion-rewriting-on-Python-3.10-plus.patch diff --git a/0001-Fix-assertion-rewriting-on-Python-3.10-plus.patch b/0001-Fix-assertion-rewriting-on-Python-3.10-plus.patch new file mode 100644 index 0000000..a80c735 --- /dev/null +++ b/0001-Fix-assertion-rewriting-on-Python-3.10-plus.patch @@ -0,0 +1,63 @@ +From 0e45c14ab59d8ca0432844739b6b3b02a40b4c71 Mon Sep 17 00:00:00 2001 +From: Accessac +Date: Tue, 2 Apr 2024 11:38:48 +0800 +Subject: [PATCH 1/1] Fix assertion rewriting on Python 3.10+ + +Origin: +https://github.com/pytest-dev/pytest/pull/8540 + +--- + src/_pytest/assertion/rewrite.py | 26 ++++++++++++++++++++------ + 1 file changed, 20 insertions(+), 6 deletions(-) + +diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py +index 805d4c8..37ff076 100644 +--- a/src/_pytest/assertion/rewrite.py ++++ b/src/_pytest/assertion/rewrite.py +@@ -673,12 +673,9 @@ class AssertionRewriter(ast.NodeVisitor): + if not mod.body: + # Nothing to do. + return +- # Insert some special imports at the top of the module but after any +- # docstrings and __future__ imports. +- aliases = [ +- ast.alias("builtins", "@py_builtins"), +- ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), +- ] ++ ++ # We'll insert some special imports at the top of the module, but after any ++ # docstrings and __future__ imports, so first figure out where that is. + doc = getattr(mod, "docstring", None) + expect_docstring = doc is None + if doc is not None and self.is_rewrite_disabled(doc): +@@ -710,10 +707,27 @@ class AssertionRewriter(ast.NodeVisitor): + lineno = item.decorator_list[0].lineno + else: + lineno = item.lineno ++ # Now actually insert the special imports. ++ if sys.version_info >= (3, 10): ++ aliases = [ ++ ast.alias("builtins", "@py_builtins", lineno=lineno, col_offset=0), ++ ast.alias( ++ "_pytest.assertion.rewrite", ++ "@pytest_ar", ++ lineno=lineno, ++ col_offset=0, ++ ), ++ ] ++ else: ++ aliases = [ ++ ast.alias("builtins", "@py_builtins"), ++ ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), ++ ] + imports = [ + ast.Import([alias], lineno=lineno, col_offset=0) for alias in aliases + ] + mod.body[pos:pos] = imports ++ + # Collect asserts. + nodes: List[ast.AST] = [mod] + while nodes: +-- +2.43.0 + diff --git a/pytest.spec b/pytest.spec index cd1d3e5..6ded4c3 100644 --- a/pytest.spec +++ b/pytest.spec @@ -1,10 +1,11 @@ Name: pytest Version: 6.2.2 -Release: 3 +Release: 4 Summary: Simple powerful testing with Python License: MIT URL: https://pytest.org Source0: https://files.pythonhosted.org/packages/d1/80/b4f47a1f933699cd531a7b336a6f3d82912e3e5e66e4a3bb1d8f0d1d98b0/pytest-6.2.2.tar.gz +Patch1: 0001-Fix-assertion-rewriting-on-Python-3.10-plus.patch %bcond_with tests %bcond_with optional_tests @@ -122,6 +123,9 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} \ %doc CHANGELOG.html README.html CONTRIBUTING.html _htmldocs/html %changelog +* Tue Apr 02 2024 Han Guangyu - 6.2.2-4 +- Add Patch1 0001-Fix-assertion-rewriting-on-Python-3.10-plus.patch + * Thu Jan 06 2022 shixuantong - 6.2.2-3 - change python3-packaging buildrequires -- Gitee