Skip to content

gh-62824: Adjust test_alias_modules_exist test to allow .pyc codec files #134777

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

Merged
merged 3 commits into from
May 27, 2025

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented May 27, 2025

In Fedora, we install many codecs as .pyc files to save space.

This test was failing when running from installed Python:

======================================================================
FAIL: test_alias_modules_exist (test.test_codecs.TransformCodecTest.test_alias_modules_exist)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.14/test/test_codecs.py", line 3115, in test_alias_modules_exist
    self.assertTrue(os.path.isfile(codec_file),
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    "Codec file not found: " + codec_file)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true : Codec file not found: /usr/lib64/python3.14/encodings/cp037.py

----------------------------------------------------------------------

…dec files

In Fedora, we install many codecs as .pyc files to save space.

This test was failing when running from installed Python:

    ======================================================================
    FAIL: test_alias_modules_exist (test.test_codecs.TransformCodecTest.test_alias_modules_exist)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib64/python3.14/test/test_codecs.py", line 3115, in test_alias_modules_exist
        self.assertTrue(os.path.isfile(codec_file),
        ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        "Codec file not found: " + codec_file)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: False is not true : Codec file not found: /usr/lib64/python3.14/encodings/cp037.py

    ----------------------------------------------------------------------
@malemburg
Copy link
Member

I think it would be better to not go look for module files (they can also be frozen or in a ZIP file), but instead try to import them.

@hroncok hroncok force-pushed the test_alias_modules_exist_pyc branch from 15dd8af to 21c1e40 Compare May 27, 2025 07:47
@hroncok
Copy link
Contributor Author

hroncok commented May 27, 2025

I think it would be better to not go look for module files (they can also be frozen or in a ZIP file), but instead try to import them.

Indeed. I added a commit to switch to importlib.util.find_spec("encodings.xxx")

@malemburg
Copy link
Member

Do you want to add a news entry or should we skip this ?

@hroncok
Copy link
Contributor Author

hroncok commented May 27, 2025

I assumed this is a skip news material.

@malemburg
Copy link
Member

I added the label, but the branch is out of date. Could you please rebase it ?

@malemburg
Copy link
Member

Ah, all good now.

@malemburg malemburg merged commit 8704d6b into python:main May 27, 2025
40 checks passed
@malemburg
Copy link
Member

Thanks for the fix, @hroncok

@hroncok hroncok deleted the test_alias_modules_exist_pyc branch May 27, 2025 08:26
@hroncok
Copy link
Contributor Author

hroncok commented May 27, 2025

Can we get a backport for 3.14 please?

@malemburg malemburg added the needs backport to 3.14 bugs and security fixes label May 27, 2025
@miss-islington-app
Copy link

Thanks @hroncok for the PR, and @malemburg for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 27, 2025
…nstead of file checks (pythonGH-134777)

(cherry picked from commit 8704d6b)

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
@bedevere-app
Copy link

bedevere-app bot commented May 27, 2025

GH-134781 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 27, 2025
encukou pushed a commit that referenced this pull request May 27, 2025
…instead of file checks (GH-134777) (GH-134781)

gh-62824: Adjust test_alias_modules_exist test to use imports instead of file checks (GH-134777)
(cherry picked from commit 8704d6b)

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants