Opened 4 months ago

Closed 4 months ago

#32994 closed Cleanup/optimization (fixed)

Invoking runtests with a CLI prelude causes utils_tests failures

Reported by: Keryn Knight Owned by: Jonny Park
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It may not be worth fixing, for all that it's somewhat obvious what has happened, but running:

python -m cProfile --sort=time runtests.py

causes the following failures:

======================================================================
FAIL: test_manage_py (utils_tests.test_autoreload.RestartWithReloaderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kez/Code/django/tests/utils_tests/test_autoreload.py", line 480, in test_manage_py
    self.assertEqual(
AssertionError: Lists differ: ['/us[20 chars]l', '-m', 'cProfile', 'runserver'] != ['/us[20 chars]l', '/var/folders/rv/jpsxqc0x5ks0_8jtn67b5psw0[55 chars]ver']

First differing element 2:
'-m'
'/var/folders/rv/jpsxqc0x5ks0_8jtn67b5psw0[41 chars]e.py'

First list contains 1 additional elements.
First extra element 4:
'runserver'

- ['/usr/bin/python', '-Wall', '-m', 'cProfile', 'runserver']
+ ['/usr/bin/python',
+  '-Wall',
+  '/var/folders/rv/jpsxqc0x5ks0_8jtn67b5psw0000gn/T/django_y2ubxvqz/tmp5ruspi9z/manage.py',
+  'runserver']
======================================================================
FAIL: test_entrypoint_fallback (utils_tests.test_autoreload.TestChildArguments)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kez/.asdf/installs/python/3.9.5/lib/python3.9/unittest/mock.py", line 1337, in patched
    return func(*newargs, **newkeywargs)
  File "/Users/kez/Code/django/tests/utils_tests/test_autoreload.py", line 219, in test_entrypoint_fallback
    self.assertEqual(
AssertionError: Lists differ: ['/Us[49 chars]on', '-m', 'cProfile', 'runserver'] != ['/Us[49 chars]on', PosixPath('/var/folders/rv/jpsxqc0x5ks0_8[80 chars]ver']

First differing element 1:
'-m'
PosixPath('/var/folders/rv/jpsxqc0x5ks0_8[66 chars].py')

First list contains 1 additional elements.
First extra element 3:
'runserver'

  ['/Users/kez/Code/django/.direnv/python-3.9.5/bin/python',
+  PosixPath('/var/folders/rv/jpsxqc0x5ks0_8jtn67b5psw0000gn/T/django_y2ubxvqz/tmpqd44gzim/django-admin-script.py'),
-  '-m',
-  'cProfile',
   'runserver']
======================================================================
FAIL: test_exe_fallback (utils_tests.test_autoreload.TestChildArguments)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kez/.asdf/installs/python/3.9.5/lib/python3.9/unittest/mock.py", line 1337, in patched
    return func(*newargs, **newkeywargs)
  File "/Users/kez/Code/django/tests/utils_tests/test_autoreload.py", line 208, in test_exe_fallback
    self.assertEqual(
AssertionError: Lists differ: ['/Users/kez/Code/django/.direnv/python-3.[42 chars]ver'] != [PosixPath('/var/folders/rv/jpsxqc0x5ks0_8[74 chars]ver']

First differing element 0:
'/Users/kez/Code/django/.direnv/python-3.9.5/bin/python'
PosixPath('/var/folders/rv/jpsxqc0x5ks0_8[60 chars]exe')

First list contains 2 additional elements.
First extra element 2:
'cProfile'

+ [PosixPath('/var/folders/rv/jpsxqc0x5ks0_8jtn67b5psw0000gn/T/django_y2ubxvqz/tmpjbmy1tyg/django-admin.exe'),
- ['/Users/kez/Code/django/.direnv/python-3.9.5/bin/python',
-  '-m',
-  'cProfile',
   'runserver']
======================================================================
FAIL: test_raises_runtimeerror (utils_tests.test_autoreload.TestChildArguments)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kez/.asdf/installs/python/3.9.5/lib/python3.9/unittest/mock.py", line 1337, in patched
    return func(*newargs, **newkeywargs)
  File "/Users/kez/Code/django/tests/utils_tests/test_autoreload.py", line 229, in test_raises_runtimeerror
    autoreload.get_child_arguments()
  File "/Users/kez/.asdf/installs/python/3.9.5/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)
  File "/Users/kez/Code/django/django/test/testcases.py", line 686, in _assert_raises_or_warns_cm
    yield cm
AssertionError: RuntimeError not raised
======================================================================
FAIL: test_warnoptions (utils_tests.test_autoreload.TestChildArguments)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kez/.asdf/installs/python/3.9.5/lib/python3.9/unittest/mock.py", line 1337, in patched
    return func(*newargs, **newkeywargs)
  File "/Users/kez/Code/django/tests/utils_tests/test_autoreload.py", line 197, in test_warnoptions
    self.assertEqual(
AssertionError: Lists differ: ['/Us[61 chars]r', '-m', 'cProfile', 'runserver'] != ['/Us[61 chars]r', '/Users/kez/Code/django/tests/utils_tests/[28 chars]ver']

First differing element 2:
'-m'
'/Users/kez/Code/django/tests/utils_tests/test_autoreload.py'

First list contains 1 additional elements.
First extra element 4:
'runserver'

  ['/Users/kez/Code/django/.direnv/python-3.9.5/bin/python',
   '-Werror',
+  '/Users/kez/Code/django/tests/utils_tests/test_autoreload.py',
-  '-m',
-  'cProfile',
   'runserver']

Change History (6)

comment:1 Changed 4 months ago by Mariusz Felisiak

Component: Testing frameworkCore (Other)
Triage Stage: UnreviewedAccepted

comment:2 Changed 4 months ago by Jonny Park

Owner: changed from nobody to Jonny Park
Status: newassigned

comment:3 Changed 4 months ago by Jonny Park

Tests in description assumes __main__.__spec__ value to be None, but running the test with -m option make some change in __main__.__spec__ thus gives unexpected result. I fixed the issue by mocking __main__.__spec__ and did a pull request at https://github.com/django/django/pull/14772

Last edited 4 months ago by Jonny Park (previous) (diff)

comment:4 Changed 4 months ago by Jacob Walls

Has patch: set

comment:5 Changed 4 months ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

comment:6 Changed 4 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 4e8121e8:

Fixed #32994 -- Fixed autoreloader tests when using 'python -m'.

Note: See TracTickets for help on using tickets.
Back to Top