Skip to content
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

gh-131290: fix direct test files invocation #131371

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

MaximGit1
Copy link

@MaximGit1 MaximGit1 commented Mar 17, 2025

Now tests are launched via ./python.exe and work correctly

added environment variable value "PYTHONREGRTEST_UNICODE_GUARD0" when calling the test directly
added spec for test when calling directly
Copy link

cpython-cla-bot bot commented Mar 17, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label Mar 17, 2025
@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@picnixz picnixz changed the title gh-131290: Several tests are modified when called directly via ./python Lib/test/... gh-131290: fix direct test files invocation Mar 17, 2025
@sobolevn sobolevn requested a review from Eclips4 March 17, 2025 17:30
@@ -260,4 +260,12 @@ def test_module_has_no_spec(self):


if __name__ == "__main__":
import importlib.util

# Adding the __spec__ attribute to the __main__ module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which test is failing because of the lack of __spec__?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_others

user\cpython\Lib\test\test_pyclbr.py", line 226, in test_others
    cm(
    ~~^
        'pdb',
        ^^^^^^
        # pyclbr does not handle elegantly `typing` or properties
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        ignore=('Union', '_ModuleTarget', '_ScriptTarget', '_ZipTarget', 'curframe_locals'),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
 File "user\cpython\Lib\test\test_pyclbr.py", line 142, in checkModule
    self.assertHaskey(dict, name, ignore)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "user\cpython\Lib\test\test_pyclbr.py", line 39, in assertHaskey
    self.assertIn(key, obj)
    ~~~~~~~~~~~~~^^^^^^^^^^
AssertionError: 'Pdb' not found in {'contextmanager': <pyclbr.Function object at 0x000001DA2A910690>}

----------------------------------------------------------------------
Ran 6 tests in 11.022s

FAILED (failures=1, errors=1)

Comment on lines 2551 to 2552
os.environ['PYTHONREGRTEST_UNICODE_GUARD'] = 'some_value' # for test_unicode_guard_env
unittest.main()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
os.environ['PYTHONREGRTEST_UNICODE_GUARD'] = 'some_value' # for test_unicode_guard_env
unittest.main()
with EnvironmentVarGuard() as env:
# for test_unicode_guard_env
PYTHONREGRTEST_UNICODE_GUARD = "some_value"
unittest.main()

and add some from test.support.os_hepler import EnvironmentVarGuard top-level import. However, I don't know if this is correct to test test_unicode_guard_env like this or if we shouldn't just skip if it we're running it from __main__. Namely, decorate the test with @unittest.skipIf(__name__ == '__main__') cc @vstinner

@picnixz picnixz changed the title gh-131290: fix direct test files invocation fix direct test files invocation Mar 17, 2025
@picnixz picnixz changed the title fix direct test files invocation gh-131290: fix direct test files invocation Mar 17, 2025
@picnixz
Copy link
Member

picnixz commented Mar 17, 2025

  • The CLA needs to be signed.
  • The NEWS entry seems to fail but I don't know if it's because of its name or if it's because of its content.

@vstinner
Copy link
Member

For regrtest, I would prefer this fix:

diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 510c8f69631..7e317d5ab94 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -2546,4 +2546,5 @@ def test_test_result_get_state(self):
 
 
 if __name__ == '__main__':
+    setup.setup_process()
     unittest.main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants