Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
python-django
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Debian Python Team
packages
python-django
Commits
8a412be6
Verified
Commit
8a412be6
authored
2 years ago
by
Lena Voytek
Committed by
Jochen Sprickerhof
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make unit tests compatible with Python 3.11 to fix build errors
Closes: #1026476 LP: #2002012
parent
1629ce8b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
debian/patches/0012-Add-Python-3.11-support-for-tests.patch
+115
-0
115 additions, 0 deletions
debian/patches/0012-Add-Python-3.11-support-for-tests.patch
debian/patches/series
+1
-0
1 addition, 0 deletions
debian/patches/series
with
116 additions
and
0 deletions
debian/patches/0012-Add-Python-3.11-support-for-tests.patch
0 → 100644
+
115
−
0
View file @
8a412be6
Description: Fix test_runner/test_utils tests on Python 3.11+.
Python 3.11 uses fully qualified test name in unittest output. See
https://github.com/python/cpython/commit/755be9b1505af591b9f2ee424a6525b6c2b65ce9
Note: This is a temporary patch for Django 3.2 to maintain compatibility with
Python 3.11 while transitioning to Django 4.x
Author: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Origin: upstream, https://github.com/django/django/commit/2ee4caf56b8e000cabbb73ad81ff05738d6d0a35
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-django/+bug/2002012
Forwarded: no
Last-Update: 2023-01-06
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/django/utils/version.py
+++ b/django/utils/version.py
@@ -15,6 +15,7 @@
PY38 = sys.version_info >= (3, 8)
PY39 = sys.version_info >= (3, 9)
PY310 = sys.version_info >= (3, 10)
+PY311 = sys.version_info >= (3, 11)
def get_version(version=None):
--- a/tests/test_runner/test_debug_sql.py
+++ b/tests/test_runner/test_debug_sql.py
@@ -4,6 +4,7 @@
from django.db import connection
from django.test import TestCase
from django.test.runner import DiscoverRunner
+from django.utils.version import PY311
from .models import Person
@@ -100,14 +101,17 @@
'''"test_runner_person"."first_name" = 'subtest-fail';'''),
]
+ # Python 3.11 uses fully qualified test name in the output.
+ method_name = ".runTest" if PY311 else ""
+ test_class_path = "test_runner.test_debug_sql.TestDebugSQL"
verbose_expected_outputs = [
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.FailingTest) ... FAIL',
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.ErrorTest) ... ERROR',
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.PassingTest) ... ok',
+ f"runTest ({test_class_path}.FailingTest{method_name}) ... FAIL",
+ f"runTest ({test_class_path}.ErrorTest{method_name}) ... ERROR",
+ f"runTest ({test_class_path}.PassingTest{method_name}) ... ok",
# If there are errors/failures in subtests but not in test itself,
# the status is not written. That behavior comes from Python.
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.FailingSubTest) ...',
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.ErrorSubTest) ...',
+ f"runTest ({test_class_path}.FailingSubTest{method_name}) ...",
+ f"runTest ({test_class_path}.ErrorSubTest{method_name}) ...",
('''SELECT COUNT(*) AS "__count" '''
'''FROM "test_runner_person" WHERE '''
'''"test_runner_person"."first_name" = 'pass';'''),
--- a/tests/test_runner/test_parallel.py
+++ b/tests/test_runner/test_parallel.py
@@ -2,7 +2,7 @@
from django.test import SimpleTestCase
from django.test.runner import RemoteTestResult
-from django.utils.version import PY37
+from django.utils.version import PY37, PY311
try:
import tblib
@@ -79,7 +79,11 @@
event = events[1]
self.assertEqual(event[0], 'addSubTest')
- self.assertEqual(str(event[2]), 'dummy_test (test_runner.test_parallel.SampleFailingSubtest) (index=0)')
+ self.assertEqual(str(event[2]),
+ "dummy_test (test_runner.test_parallel.SampleFailingSubtest%s) (index=0)"
+ # Python 3.11 uses fully qualified test name in the output.
+ % (".dummy_test" if PY311 else ""),
+ )
trailing_comma = '' if PY37 else ','
self.assertEqual(repr(event[3][1]), "AssertionError('0 != 1'%s)" % trailing_comma)
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -26,6 +26,7 @@
)
from django.urls import NoReverseMatch, path, reverse, reverse_lazy
from django.utils.deprecation import RemovedInDjango41Warning
+from django.utils.version import PY311
from .models import Car, Person, PossessedCar
from .views import empty_response
@@ -78,9 +79,11 @@
SkipTestCase('test_foo').test_foo,
ValueError,
"skipUnlessDBFeature cannot be used on test_foo (test_utils.tests."
- "SkippingTestCase.test_skip_unless_db_feature.<locals>.SkipTestCase) "
+ "SkippingTestCase.test_skip_unless_db_feature.<locals>.SkipTestCase%s) "
"as SkippingTestCase.test_skip_unless_db_feature.<locals>.SkipTestCase "
"doesn't allow queries against the 'default' database."
+ # Python 3.11 uses fully qualified test name in the output.
+ % (".test_foo" if PY311 else ""),
)
def test_skip_if_db_feature(self):
@@ -122,9 +125,11 @@
SkipTestCase('test_foo').test_foo,
ValueError,
"skipIfDBFeature cannot be used on test_foo (test_utils.tests."
- "SkippingTestCase.test_skip_if_db_feature.<locals>.SkipTestCase) "
+ "SkippingTestCase.test_skip_if_db_feature.<locals>.SkipTestCase%s) "
"as SkippingTestCase.test_skip_if_db_feature.<locals>.SkipTestCase "
"doesn't allow queries against the 'default' database."
+ # Python 3.11 uses fully qualified test name in the output.
+ % (".test_foo" if PY311 else ""),
)
This diff is collapsed.
Click to expand it.
debian/patches/series
+
1
−
0
View file @
8a412be6
...
...
@@ -9,3 +9,4 @@
0009-Fixed-33282-Fixed-a-crash-when-OR-ing-subquery-and-a.patch
0010-Fixed-inspectdb.tests.InspectDBTestCase.test_custom_.patch
0011-Moved-RequestSite-import-to-the-toplevel.patch
0012-Add-Python-3.11-support-for-tests.patch
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment