Skip to content

test_pickle tests failing when invoked directly #131031

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
donBarbos opened this issue Mar 10, 2025 · 1 comment
Open

test_pickle tests failing when invoked directly #131031

donBarbos opened this issue Mar 10, 2025 · 1 comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@donBarbos
Copy link
Contributor

donBarbos commented Mar 10, 2025

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

@tomasr8 tomasr8 added the tests Tests in the Lib/test dir label Mar 10, 2025
@picnixz picnixz added the type-bug An unexpected behavior, bug, or error label Mar 12, 2025
@donBarbos donBarbos changed the title tests test_pickle failed due to error message mismatch test_pickle tests failing when invoked directly May 3, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 3, 2025
@serhiy-storchaka
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

4 participants