Repository navigation
Some test modules fail when run as a script #104057
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 1, 2023 - changed the title
[-]Running test_module file directly fails[/-][+]Some test modules fail when run as a script[/+]on May 1, 2023 I grepped with IDLE for other candidates to fix.
Searching "<class 'test." in F:\dev\3x\Lib\test\*.py ... F:\dev\3x\Lib\test\test_descrtut.py: 42: <class 'test.test_descrtut.defaultdict'> F:\dev\3x\Lib\test\test_descrtut.py: 49: <class 'test.test_descrtut.defaultdict'> F:\dev\3x\Lib\test\test_descrtut.py: 51: <class 'test.test_descrtut.defaultdict'> F:\dev\3x\Lib\test\test_descrtut.py: 267: classmethod <class 'test.test_descrtut.C'> 1 F:\dev\3x\Lib\test\test_descrtut.py: 270: classmethod <class 'test.test_descrtut.C'> 1 F:\dev\3x\Lib\test\test_descrtut.py: 276: classmethod <class 'test.test_descrtut.D'> 1 F:\dev\3x\Lib\test\test_descrtut.py: 279: classmethod <class 'test.test_descrtut.D'> 1 F:\dev\3x\Lib\test\test_descrtut.py: 295: classmethod <class 'test.test_descrtut.C'> 1 F:\dev\3x\Lib\test\test_descrtut.py: 299: classmethod <class 'test.test_descrtut.C'> 1 F:\dev\3x\Lib\test\test_metaclass.py: 121: Prepare called: ('C', (<class 'test.test_metaclass.B'>, <class 'object'>)) {'other': 'haha'} F:\dev\3x\Lib\test\test_module.py: 239: repr(m), "<module 'foo' (<class 'test.test_module.FullLoader'>)>") F:\dev\3x\Lib\test\test_pdb.py: 582: <class 'test.test_pdb.MyClass'> F:\dev\3x\Lib\test\test_typing.py: 120: "<class 'test.test_typing.AnyTests.test_repr.<locals>.Sub'>", Hits found: 13 (Hint: right-click to open locations.)This caught the test_module line you just fixed. Some of these are in interactive output and I don't know if they will fail.
Yeah, I saw these lines, and this should be discussed. Otherwise, I found some another scenarios with the same issue (easy to fix).
However, I'll try to run file
test_supporton Windows and got interpreter crash. Can someone confirm that?
./python Lib/test/test_support.py
Cannot confirm this on Linux.
Please, use the current main branch if you try to reproduce it.main built yesterday
F:\dev\3x>python -m test.test_support Running Debug|x64 interpreter... .....................s.F..Crash. Rebuild and try again. Same crash. "Debug assertion Failed."
File minkernel/ctrs/ucrt/src/appcrt/lowio/write.cpp line 50, expression(_osfile(fh) & FOPEN)F:\dev\3x>python -m test.test_support Running Debug|x64 interpreter... .....................s.F..Crash. Rebuild and try again. Same crash. "Debug assertion Failed."
File minkernel/ctrs/ucrt/src/appcrt/lowio/write.cpp line 50, expression(_osfile(fh) & FOPEN)Thanks!
I think, it's a minimal reproducible example:import os def make_bad_fd(): file = open("test_file.txt", "wb") try: return file.fileno() finally: file.close() fd = make_bad_fd() os.write(fd, b"foo")
f:\dev\3x>python -m test -uall -v test_supportruns fine.Running test_support from IDLE editor: get same Assertion Failure box. After Ignore, failure is
.....................s.F.......s.........s... ====================================================================== FAIL: test_ignored_deprecations_are_silent (__main__.TestSupport.test_ignored_deprecations_are_silent) Test support.ignore_deprecations_from() silences warnings ---------------------------------------------------------------------- Traceback (most recent call last): File "f:\dev\3x\Lib\test\test_support.py", line 52, in test_ignored_deprecations_are_silent self.assertEqual(len(messages), 0, messages) AssertionError: 1 != 0 : ['You should NOT be seeing this.']f:\dev\3x>python -m test -uall -v test_supportruns fine.Running test_support from IDLE editor: get same Assertion Failure box. After Ignore, failure is
.....................s.F.......s.........s... ====================================================================== FAIL: test_ignored_deprecations_are_silent (__main__.TestSupport.test_ignored_deprecations_are_silent) Test support.ignore_deprecations_from() silences warnings ---------------------------------------------------------------------- Traceback (most recent call last): File "f:\dev\3x\Lib\test\test_support.py", line 52, in test_ignored_deprecations_are_silent self.assertEqual(len(messages), 0, messages) AssertionError: 1 != 0 : ['You should NOT be seeing this.']That's easy to fix. Just replace
cls._test_support_token = support.ignore_deprecations_from( "test.test_support", like=".*You should NOT be seeing this.*" )
to this:
cls._test_support_token = support.ignore_deprecations_from( __main__, like=".*You should NOT be seeing this.*" )
- added a commit that references this issue
on May 1, 2023 1 remaining item
Same is for
test_descrtutandtest_extcall.test_peg_generatorandtest_importlibfail too, but for other reason. Actually, there are a lot of tests that fail when directly invoked. For example, all tests that importasyncio(or some other module that does it) fail with the same exception:$ grep -r "^import asyncio" Lib/test/test_*.py Lib/test/test_builtin.py:import asyncio Lib/test/test_contextlib_async.py:import asyncio Lib/test/test_inspect.py:import asyncio Lib/test/test_logging.py:import asyncio Lib/test/test_os.py:import asyncio Lib/test/test_sys_settrace.py:import asyncio $ ./python Lib/test/test_pdb.py Traceback (most recent call last): File "/home/.../cpython/Lib/test/test_pdb.py", line 20, in <module> from unittest.mock import patch File "/home/.../cpython/Lib/unittest/mock.py", line 26, in <module> import asyncio File "/home/.../cpython/Lib/asyncio/__init__.py", line 8, in <module> from .base_events import * File "/home/.../cpython/Lib/asyncio/base_events.py", line 45, in <module> from . import staggered File "/home/.../cpython/Lib/asyncio/staggered.py", line 11, in <module> from . import tasks File "/home/.../cpython/Lib/asyncio/tasks.py", line 946, in <module> eager_task_factory = create_eager_task_factory(Task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/.../cpython/Lib/asyncio/tasks.py", line 936, in create_eager_task_factory raise TypeError( TypeError: Provided constructor does not support eager task executionFor example, all tests that import
asyncio(or some other module that does it) fail with the same exception:Please, read the #104070, I think you got the same problem
For example, all tests that import
asyncio(or some other module that does it) fail with the same exception:Please, read the #104070, I think you got the same problem
Yep, you're right. A lot of modules still fail for other reasons though.
Reacted by Kirill Podoprigoramain built yesterday
F:\dev\3x>python -m test.test_support Running Debug|x64 interpreter... .....................s.F..Crash. Rebuild and try again. Same crash. "Debug assertion Failed." File minkernel/ctrs/ucrt/src/appcrt/lowio/write.cpp line 50, expression
(_osfile(fh) & FOPEN)If you run a test directly, such as
python_d -m test.test_support -vv -k test_make_bad_fd, then the reporting modes and reporting files for the debug C runtime's non-standard- assertions -- i.e. the macros
_ASSERT,_ASSERTE, and_ASSERT_EXPR, or the macros_RPT0and_RPTNused with the_CRT_ASSERTreport type; - warnings -- i.e. the macros
_RPT0and_RPTNused with the_CRT_WARNreport type; and - errors -- i.e. the macros
_RPT0and_RPTNused with the_CRT_ERRORreport type --
all remain set to their default values. The assertion and error report types default to showing a dialog box, while the warning report type defaults to outputting a message to an attached debugger, if any. For example:
>>> from msvcrt import * >>> CrtSetReportMode(CRT_ASSERT, CRTDBG_REPORT_MODE) == CRTDBG_MODE_WNDW True >>> CrtSetReportMode(CRT_ERROR, CRTDBG_REPORT_MODE) == CRTDBG_MODE_WNDW True >>> CrtSetReportMode(CRT_WARN, CRTDBG_REPORT_MODE) == CRTDBG_MODE_DEBUG True
On the other hand, if you run the main test suite normally, such as
python_d -m test test_support -vv -m test_make_bad_fd, then_CrtSetReportMode()and_CrtSetReportFile()get called to configure the report mode for the_CRT_ASSERT,_CRT_WARN, and_CRT_ERRORreport types. They either get configured to no reporting (i.e. mode 0) or, if verbose mode is enabled (i.e.-vvcommand-line option) to reporting to stderr (i.e._CRTDBG_MODE_FILEmode with the file set to_CRTDBG_FILE_STDERR). Also, WinAPISetErrorMode()is called withSEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOXin order to suppress any message boxes due to system error reporting.
One step that's missing is to explicitly configure the report mode for the standard
assertmacro in debug builds. This gets configured by the C runtime's_set_error_mode()function. For a console application (e.g. "python.exe"), the default behavior is to write to stderr (i.e._OUT_TO_STDERR), which is what we want. On the other hand, for a GUI application (e.g. "pythonw.exe"), the default behavior is to show a message box (i.e._OUT_TO_MSGBOX). If we add any tests that specifically use "pythonw.exe" instead of "python.exe", then we should explicitly configure_set_error_mode(_OUT_TO_STDERR), particularly in theSuppressCrashReportcontext manager, and ensure that the "pythonw.exe" process is spawned with a valid stderr file. Also, it appears that themsvcrtmodule wraps theset_error_mode()function, but it doesn't define the required constantsOUT_TO_DEFAULT,OUT_TO_STDERR,OUT_TO_MSGBOX, andREPORT_ERRMODE. That oversight should be corrected.- assertions -- i.e. the macros
You're running the tests incorrectly for how the debug build is supported on Windows. The debug CRT report modes are not set for each individual test, except in test cases that explicitly use the
SuppressCrashReport()context manager. Generally you have to run the main test suite and supply the test you want to run as a command-line option, with an optional-mfilter for test cases and-vvif you want the debug CRT assertion, warning and error messages written to stderr. For example:python_d -m test test_support -vv -m test_make_bad_fd.@eryksun, are you replying to me? I use Linux, so I guess that none of errors that I mentioned above relate to how test output is handled by system, and most of them happen regardless of
-mflag usage (but doesn't happen iflibregrtestis involved, i.e. as inpython -m test test_supportexample).- added a commit that references this issue
on May 2, 2023 - added a commit that references this issue
on May 11, 2023 Thanks for the fixes! Anything left here, or okay to close?
Thanks for the fixes! Anything left here, or okay to close?
I think we did everything we had to do :)
Thanks for the remind, Hugo!Reacted by Hugo van Kemenade
I'll soon send a PR to fix it.
Linked PRs