Skip to content

test.test_sys.TestRemoteExec fails with AssertionError #132143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
littlebutt opened this issue Apr 6, 2025 · 6 comments
Open

test.test_sys.TestRemoteExec fails with AssertionError #132143

littlebutt opened this issue Apr 6, 2025 · 6 comments
Labels
3.14 new features, bugs and security fixes OS-windows tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@littlebutt
Copy link
Contributor

littlebutt commented Apr 6, 2025

Bug report

Bug description:

The test case test_sys failed when I ran rt.bat test_sys. The unittest report is as follow

FAIL: test_remote_exec_raises_audit_event (test.test_sys.TestRemoteExec.test_remote_exec_raises_audit_event)
Test remote exec raises an audit event
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\project\cpython\Lib\test\test_sys.py", line 2106, in test_remote_exec_raises_audit_event
    self.assertIn(b"Remote script executed successfully!", stdout)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: b'Remote script executed successfully!' not found in b'Target process running...\r\n'

----------------------------------------------------------------------
Ran 90 tests in 1.495s

FAILED (failures=1, skipped=7)
test test_sys failed

== Tests result: FAILURE ==

It seems that the problem is caused by an unfinished subprocess since it runs synchronizely. However, when I commented the first two assertion statements.

        # self.assertIn(b"Remote script executed successfully!", stdout)
        # self.assertIn(b"Audit event: remote_debugger_script, arg: ", stdout)
        self.assertEqual(stderr, b"")

The stderr is printed out as follow

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\project\cpython\Lib\test\test_sys.py", line 2108, in test_remote_exec_raises_audit_event
    self.assertEqual(stderr, b"")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
AssertionError: b'Exception ignored in audit hook:\r\nTrace[295 chars]\r\n' != b''

OS: Windows 10 22H2

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

@littlebutt littlebutt added the type-bug An unexpected behavior, bug, or error label Apr 6, 2025
@chris-eibl chris-eibl added OS-windows 3.14 new features, bugs and security fixes labels Apr 6, 2025
@chris-eibl
Copy link
Member

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\project\cpython\Lib\test\test_sys.py", line 2108, in test_remote_exec_raises_audit_event
    self.assertEqual(stderr, b"")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
AssertionError: b'Exception ignored in audit hook:\r\nTrace[295 chars]\r\n' != b''

Can you print stderr so we can get the full traceback to narrow down the problem?

@chris-eibl chris-eibl changed the title Test case test_sys fails with AssertionError Test case test.test_sys.TestRemoteExec.test_remote_exec_raises_audit_event fails with AssertionError Apr 6, 2025
@chris-eibl chris-eibl changed the title Test case test.test_sys.TestRemoteExec.test_remote_exec_raises_audit_event fails with AssertionError test.test_sys.TestRemoteExec fails with AssertionError Apr 6, 2025
@littlebutt
Copy link
Contributor Author

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\project\cpython\Lib\test\test_sys.py", line 2108, in test_remote_exec_raises_audit_event
    self.assertEqual(stderr, b"")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
AssertionError: b'Exception ignored in audit hook:\r\nTrace[295 chars]\r\n' != b''

Can you print stderr so we can get the full traceback to narrow down the problem?

I printed out stderr and it looks like a locale codec problem

AssertionError: Exception ignored in audit hook:

Traceback (most recent call last):

  File "C:\Users\Administrator\Desktop\project\cpython\build\test_python_16424\xe6\@test_16424_tmp\xe6_target.py", line 12, in audit_hook

UnicodeEncodeError: 'gbk' codec can't encode character '\xe6' in position 229: illegal multibyte sequence

I think it is not a serious problem :)

@chris-eibl
Copy link
Member

Great - that helps. Seems to stem from

cpython/Lib/test/test_sys.py

Lines 2097 to 2098 in 0a10b45

def audit_hook(event, arg):
print(f"Audit event: {event}, arg: {arg}")

where we should care about encoding errors when printing.

@chris-eibl chris-eibl added the tests Tests in the Lib/test dir label Apr 6, 2025
@chris-eibl chris-eibl reopened this Apr 6, 2025
@chris-eibl
Copy link
Member

I think it is not a serious problem :)

Although it is benign, I'd prefer to fix it, since that should hopefully be easy, and the tests should not depend on the host encoding.

Can you e.g. try

print(f"Audit event: {event}, arg: {arg}".encode("ascii", errors="replace"))

because the \xe6 stems from the test file name we get in as arg, which we aren't interested in?

>py -c "'\xe6'.encode('gbk')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    '\xe6'.encode('gbk')
    ~~~~~~~~~~~~~^^^^^^^
UnicodeEncodeError: 'gbk' codec can't encode character '\xe6' in position 0: illegal multibyte sequence
encoding with 'gbk' codec failed

@littlebutt
Copy link
Contributor Author

I think it is not a serious problem :)

Although it is benign, I'd prefer to fix it, since that should hopefully be easy, and the tests should not depend on the host encoding.

Can you e.g. try

print(f"Audit event: {event}, arg: {arg}".encode("ascii", errors="replace"))
because the \xe6 stems from the test file name we get in as arg, which we aren't interested in?

>py -c "'\xe6'.encode('gbk')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    '\xe6'.encode('gbk')
    ~~~~~~~~~~~~~^^^^^^^
UnicodeEncodeError: 'gbk' codec can't encode character '\xe6' in position 0: illegal multibyte sequence
encoding with 'gbk' codec failed

It works!

C:\Users\Administrator\Desktop\project\cpython\PCbuild>"C:\Users\Administrator\Desktop\project\cpython\PCbuild\amd64\python.exe"  -m test --fast-ci test_sys
+ 'C:\Users\Administrator\Desktop\project\cpython\PCbuild\amd64\python.exe' -u -W error -bb -E -m test --fast-ci test_sys --dont-add-python-opts
Using random seed: 2000276668
0:00:00 Run 1 test in parallel using 1 worker process (timeout: 10 min, worker timeout: 15 min)
0:00:01 [1/1] test_sys passed

== Tests result: SUCCESS ==

10 slowest tests:
- test_sys: 1.9 sec

1 test OK.

Total duration: 1.9 sec
Total tests: run=90 skipped=7
Total test files: run=1/1
Result: SUCCESS
About to run again without deleting .pyc first:
请按任意键继续. . .

C:\Users\Administrator\Desktop\project\cpython\PCbuild>"C:\Users\Administrator\Desktop\project\cpython\PCbuild\amd64\python.exe"  -m test --fast-ci test_sys 
+ 'C:\Users\Administrator\Desktop\project\cpython\PCbuild\amd64\python.exe' -u -W error -bb -E -m test --fast-ci test_sys --dont-add-python-opts
Using random seed: 10842553
0:00:00 Run 1 test in parallel using 1 worker process (timeout: 10 min, worker timeout: 15 min)
0:00:01 [1/1] test_sys passed

== Tests result: SUCCESS ==

10 slowest tests:
- test_sys: 1.7 sec

1 test OK.

Total duration: 1.7 sec
Total tests: run=90 skipped=7
Total test files: run=1/1
Result: SUCCESS

@chris-eibl
Copy link
Member

It works!

Great! Would you like to create a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes OS-windows tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants