Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a9c7bc0
fixed test_regrtest
MaximGit1 Mar 17, 2025
b875bee
added spec in test.test_pyclbr.py
MaximGit1 Mar 17, 2025
678893f
changed module name when calling test_metaclass.py directly
MaximGit1 Mar 17, 2025
4670696
Merge branch 'main' into fix-for-running-tests-issue-131290
MaximGit1 Mar 17, 2025
3241aeb
added Misc/NEWS
MaximGit1 Mar 17, 2025
5ffd268
Merge branch 'main' into fix-for-running-tests-issue-131290
MaximGit1 Mar 17, 2025
d3cdd6b
Apply review suggestions for test_regrtest
MaximGit1 Mar 19, 2025
682613f
added comment for test_metaclass.py
MaximGit1 Apr 6, 2025
22c996d
refactor(tests): improve structure and naming in test_pyclbr.py
MaximGit1 Apr 6, 2025
6744e91
created news file
MaximGit1 Apr 6, 2025
2509478
Update Misc/NEWS.d/next/Tests/2025-03-17-19-47-27.gh-issue-131290.NyC…
MaximGit1 Apr 6, 2025
fd29fd1
Removed new entry file NEWS
MaximGit1 Apr 6, 2025
a6868a2
Merge remote-tracking branch 'origin/fix-for-running-tests-issue-1312…
MaximGit1 Apr 6, 2025
bef8cc5
local import removed in test_pyclbr.py
MaximGit1 Apr 6, 2025
584e07b
Created contextmanager for temporarily setting __spec__ on __main__ m…
MaximGit1 Apr 6, 2025
9ec71f2
imports order changed
MaximGit1 Apr 6, 2025
2134259
refactored contextmanager
MaximGit1 Apr 7, 2025
cd3f0bb
removed test_pdb_module
MaximGit1 Apr 7, 2025
19e1a3a
changed the order of checks in the test_others function
MaximGit1 Apr 7, 2025
d12e5c6
added comment and ignores
MaximGit1 Apr 7, 2025
9e28fa4
Update Lib/test/test_pyclbr.py
MaximGit1 Apr 7, 2025
ca81976
Merge branch 'main' into fix-for-running-tests-issue-131290
picnixz Apr 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,6 @@ def load_tests(loader, tests, pattern):


if __name__ == "__main__":
# set __name__ to match doctest expectations
__name__ = "test.test_metaclass"
unittest.main()
23 changes: 18 additions & 5 deletions Lib/test/test_pyclbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def defined_in(item, module):
self.assertHaskey(dict, name, ignore)

def test_easy(self):
import importlib.util
if getattr(sys.modules["__main__"], "__spec__", None) is None:
sys.modules["__main__"].__spec__ = importlib.machinery.ModuleSpec(
name="__main__", loader=None, origin="built-in"
)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not very happy with this specific hack. Would it be possible to have some contextmanager decorator that we could apply on the test method so that the module's spec is only changed for the duration of the test?


self.checkModule('pyclbr')
# XXX: Metaclasses are not supported
# self.checkModule('ast')
Expand Down Expand Up @@ -214,6 +220,18 @@ def compare(parent1, children1, parent2, children2):

compare(None, actual, None, expected)

def test_pdb_module(self):
import importlib.util
Copy link
Member

Choose a reason for hiding this comment

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

This can be a top-level import, no need for a local one (we don't really need fast start up time for tests)

if getattr(sys.modules["__main__"], "__spec__", None) is None:
sys.modules["__main__"].__spec__ = importlib.machinery.ModuleSpec(
name="__main__", loader=None, origin="builtin"
)

self.checkModule(
'pdb',
ignore=('_ModuleTarget', '_ScriptTarget', '_ZipTarget', 'Pdb'),
)

def test_others(self):
cm = self.checkModule

Expand All @@ -223,11 +241,6 @@ def test_others(self):
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
cm(
'pdb',
# pyclbr does not handle elegantly `typing` or properties
ignore=('Union', '_ModuleTarget', '_ScriptTarget', '_ZipTarget', 'curframe_locals'),
)
cm('pydoc', ignore=('input', 'output',)) # properties

# Tests for modules inside packages
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2546,4 +2546,5 @@ def test_test_result_get_state(self):


if __name__ == '__main__':
setup.setup_process()
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Several tests are modified when called directly via ./python Lib/test/...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Tests in :file:`Lib/test` can now be correctly executed as standalone scripts.

Several tests were modified to correctly handle execution when called directly via `./python Lib/test/...`, ensuring that the `__spec__` attribute is properly set in certain modules like `__main__`.
Loading