Skip to content

test_sys_settrace tests are not independent #108982

Closed

Description

@serhiy-storchaka

Running any of TraceOpcodesTestCase tests from test_sys_settrace always fails. For example:

$ ./python -m test -v test_sys_settrace -m test.test_sys_settrace.TraceOpcodesTestCase.test_01_basic
...
test_01_basic (test.test_sys_settrace.TraceOpcodesTestCase.test_01_basic) ... FAIL

======================================================================
FAIL: test_01_basic (test.test_sys_settrace.TraceOpcodesTestCase.test_01_basic)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/test_sys_settrace.py", line 388, in test_01_basic
    self.run_test(basic)
  File "/home/serhiy/py/cpython/Lib/test/test_sys_settrace.py", line 364, in run_test
    self.run_and_compare(func, func.events)
  File "/home/serhiy/py/cpython/Lib/test/test_sys_settrace.py", line 360, in run_and_compare
    self.compare_events(func.__code__.co_firstlineno,
  File "/home/serhiy/py/cpython/Lib/test/test_sys_settrace.py", line 1745, in compare_events
    self.assertLess(len(skip_opcode_events), len(events),
AssertionError: 3 not less than 3 : No 'opcode' events received by the tracer
...

Running several of TraceOpcodesTestCase tests only fails the first of them.

Running also RaisingTraceFuncTestCase.test_line_event_raises_before_opcode_event makes the tests passing successfully.

$ ./python -m test -v test_sys_settrace -m test.test_sys_settrace.TraceOpcodesTestCase.test_01_basic -m test_line_event_raises_before_opcode_event
...
test_line_event_raises_before_opcode_event (test.test_sys_settrace.RaisingTraceFuncTestCase.test_line_event_raises_before_opcode_event) ... ok
test_01_basic (test.test_sys_settrace.TraceOpcodesTestCase.test_01_basic) ... ok
...

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    testsTests in the Lib/test dir
    3.12only security fixes
    3.13only security fixes
    on Sep 6, 2023
  2. serhiy-storchaka commented on Sep 6, 2023

    @serhiy-storchaka
    MemberAuthor

    It is only reproduced in 3.12+.

  3. gaogaotiantian commented on Sep 6, 2023

    @gaogaotiantian
    Member

    This is a known issue #103615. I have not had the chance to fix it. The issue is that you can't start the trace before you set trace_opcode = True. It's an underlying tracing mechanism problem that requires some architecture change.

  4. serhiy-storchaka commented on Sep 6, 2023

    @serhiy-storchaka
    MemberAuthor

    Is there a workaround for tests which does not invalidate the purposes of tests?

    #103615 did not mention test_sys_settrace. Should we close this issue or keep it until #103615 be solved to ensure that this issue also is fixed?

  5. gaogaotiantian commented on Sep 6, 2023

    @gaogaotiantian
    Member

    I can do a hacky workaround if that's what needed for now - basically we just need to ensure f_trace_opcodes is set to True at least once on ANY frame before we start tracing. It that helps the validation, I can do the PR - it's pretty trivial. We should, however, remove it when it's not needed.

    #108976 is not fixed after the workaround though. It has a deeper issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13only security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions