Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9393 from rtibbles/python3.10
Python 3.10 support
- Loading branch information
Showing
8 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
This script backports this Python 3.10 compatibility fix https://github.com/pytest-dev/pytest/pull/8540 | ||
in order to allow pytest to run in Python 3.10 without upgrading to version 6.2.5 which does not support 2.7 | ||
""" | ||
import os | ||
import subprocess | ||
|
||
import pytest | ||
|
||
site_packages_dir = os.path.dirname(pytest.__file__) | ||
|
||
patch_file = os.path.join(os.path.dirname(__file__), "pytest_3.10.patch") | ||
|
||
print("Applying patch: " + str(patch_file)) | ||
|
||
# -N: insist this is FORWARD patch, don't reverse apply | ||
# -p1: strip first path component | ||
# -t: batch mode, don't ask questions | ||
patch_command = ["patch", "-N", "-p1", "-d", site_packages_dir, "-t", "-i", patch_file] | ||
print(" ".join(patch_command)) | ||
try: | ||
# Use a dry run to establish whether the patch is already applied. | ||
# If we don't check this, the patch may be partially applied (which is bad!) | ||
subprocess.check_output(patch_command + ["--dry-run"]) | ||
except subprocess.CalledProcessError as e: | ||
if e.returncode == 1: | ||
# Return code 1 means not all hunks could be applied, this usually | ||
# means the patch is already applied. | ||
print( | ||
"Warning: failed to apply patch (exit code 1), " | ||
"assuming it is already applied: ", | ||
str(patch_file), | ||
) | ||
else: | ||
raise e | ||
else: | ||
# The dry run worked, so do the real thing | ||
subprocess.check_output(patch_command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py | ||
index 4f96b9e8c..1aa5b12de 100644 | ||
--- a/_pytest/assertion/rewrite.py | ||
+++ b/_pytest/assertion/rewrite.py | ||
@@ -587,10 +587,6 @@ class AssertionRewriter(ast.NodeVisitor): | ||
return | ||
# Insert some special imports at the top of the module but after any | ||
# docstrings and __future__ imports. | ||
- aliases = [ | ||
- ast.alias(py.builtin.builtins.__name__, "@py_builtins"), | ||
- ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), | ||
- ] | ||
doc = getattr(mod, "docstring", None) | ||
expect_docstring = doc is None | ||
if doc is not None and self.is_rewrite_disabled(doc): | ||
@@ -617,6 +613,22 @@ class AssertionRewriter(ast.NodeVisitor): | ||
pos += 1 | ||
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters