Skip to content

test_pickle tests failing when invoked directly #131031

Closed

Description

@donbarbos

I ran separate tests for the pickle module on main branch:

./python ./Lib/test/test_pickle.py

I got 24 failures
Judging by the output, the problem is in the mismatch of error messages:

test_nested_lookup_error (__main__.CPicklingErrorTests.test_nested_lookup_error) ...
  test_nested_lookup_error (__main__.CPicklingErrorTests.test_nested_lookup_error) (proto=0) ... FAIL
  test_nested_lookup_error (__main__.CPicklingErrorTests.test_nested_lookup_error) (proto=1) ... FAIL
  test_nested_lookup_error (__main__.CPicklingErrorTests.test_nested_lookup_error) (proto=2) ... FAIL
  test_nested_lookup_error (__main__.CPicklingErrorTests.test_nested_lookup_error) (proto=3) ... FAIL
  test_nested_lookup_error (__main__.CPicklingErrorTests.test_nested_lookup_error) (proto=4) ... FAIL
  test_nested_lookup_error (__main__.CPicklingErrorTests.test_nested_lookup_error) (proto=5) ... FAIL
...
test_wrong_object_lookup_error (__main__.CPicklingErrorTests.test_wrong_object_lookup_error) ...
  test_wrong_object_lookup_error (__main__.CPicklingErrorTests.test_wrong_object_lookup_error) (proto=0) ... FAIL
  test_wrong_object_lookup_error (__main__.CPicklingErrorTests.test_wrong_object_lookup_error) (proto=1) ... FAIL
  test_wrong_object_lookup_error (__main__.CPicklingErrorTests.test_wrong_object_lookup_error) (proto=2) ... FAIL
  test_wrong_object_lookup_error (__main__.CPicklingErrorTests.test_wrong_object_lookup_error) (proto=3) ... FAIL
  test_wrong_object_lookup_error (__main__.CPicklingErrorTests.test_wrong_object_lookup_error) (proto=4) ... FAIL
  test_wrong_object_lookup_error (__main__.CPicklingErrorTests.test_wrong_object_lookup_error) (proto=5) ... FAIL
...
test_nested_lookup_error (__main__.PyPicklingErrorTests.test_nested_lookup_error) ...
  test_nested_lookup_error (__main__.PyPicklingErrorTests.test_nested_lookup_error) (proto=0) ... FAIL
  test_nested_lookup_error (__main__.PyPicklingErrorTests.test_nested_lookup_error) (proto=1) ... FAIL
  test_nested_lookup_error (__main__.PyPicklingErrorTests.test_nested_lookup_error) (proto=2) ... FAIL
  test_nested_lookup_error (__main__.PyPicklingErrorTests.test_nested_lookup_error) (proto=3) ... FAIL
  test_nested_lookup_error (__main__.PyPicklingErrorTests.test_nested_lookup_error) (proto=4) ... FAIL
  test_nested_lookup_error (__main__.PyPicklingErrorTests.test_nested_lookup_error) (proto=5) ... FAIL
...
test_wrong_object_lookup_error (__main__.PyPicklingErrorTests.test_wrong_object_lookup_error) ...
  test_wrong_object_lookup_error (__main__.PyPicklingErrorTests.test_wrong_object_lookup_error) (proto=0) ... FAIL
  test_wrong_object_lookup_error (__main__.PyPicklingErrorTests.test_wrong_object_lookup_error) (proto=1) ... FAIL
  test_wrong_object_lookup_error (__main__.PyPicklingErrorTests.test_wrong_object_lookup_error) (proto=2) ... FAIL
  test_wrong_object_lookup_error (__main__.PyPicklingErrorTests.test_wrong_object_lookup_error) (proto=3) ... FAIL
  test_wrong_object_lookup_error (__main__.PyPicklingErrorTests.test_wrong_object_lookup_error) (proto=4) ... FAIL
  test_wrong_object_lookup_error (__main__.PyPicklingErrorTests.test_wrong_object_lookup_error) (proto=5) ... FAIL

Examples of mismatches:

AssertionError: "type object 'AbstractPickleTests' has no attribute 'spam'" != "module '__main__' has no attribute 'AbstractPickleTests'"
- type object 'AbstractPickleTests' has no attribute 'spam'
+ module '__main__' has no attribute 'AbstractPickleTests'
...
AssertionError: "Can'[53 chars]4b0>: it's not the same object as __main__.AbstractPickleTests" != "Can'[53 chars]4b0>: it's not found as __main__.AbstractPickleTests"
- Can't pickle <test.pickletester.REX object at 0x79fcb255a4b0>: it's not the same object as __main__.AbstractPickleTests
?                                                                         ^^^^^^^^^ ^^^^^
+ Can't pickle <test.pickletester.REX object at 0x79fcb255a4b0>: it's not found as __main__.AbstractPickleTests
?

I'm going to send PR after we decide what the messages should look like

Linked PRs

Activity

  1. changed the title [-]tests `test_pickle` failed due to error message mismatch[/-] [+]`test_pickle` tests failing when invoked directly[/+] on May 3, 2025
  2. added a commit that references this issue on May 3, 2025
  3. serhiy-storchaka commented on May 3, 2025

    @serhiy-storchaka
    Member

    Good catch @donbarbos! Thank you.

    Your PR fixes tests, but I think that it would be better to not use AbstractPickleTests in these tests. For these tests we need an existing global class which does not exist in __main__ . Running tests as a script fails because AbstractPickleTests is imported in test_pickle.py which becomes __main__. #133356 uses this approach.

  4. added a commit that references this issue on May 8, 2025
  5. added a commit that references this issue on May 8, 2025
  6. added a commit that references this issue on May 8, 2025
  7. added 2 commits that reference this issue on May 8, 2025
  8. added a commit that references this issue on Jul 12, 2025
  9. added a commit that references this issue on Aug 4, 2025
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

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions