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-116303: Skip test module dependent tests if test modules are disabled #116307

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9b3f0f7
gh-116303: Skip some sqlite3 tests if testcapi is unavailable
erlend-aasland Mar 4, 2024
0f6f74e
Skip more tests
erlend-aasland Mar 4, 2024
2f750c3
Split up sqlite3 tests
erlend-aasland Mar 4, 2024
7c4477d
Amend previous commit
erlend-aasland Mar 4, 2024
a9c6f62
Pull in main
erlend-aasland Mar 4, 2024
cdc6df4
Use import_helper iso. requires_limited_api
erlend-aasland Mar 5, 2024
d05dcd7
More skips
erlend-aasland Mar 5, 2024
cb7cff4
Fix gc and weakref tests
erlend-aasland Mar 5, 2024
ad5e3b6
Remove local debug stuff
erlend-aasland Mar 5, 2024
cdb8bf4
Fix test_os
erlend-aasland Mar 5, 2024
e4a30b0
Fixup stable_abi.py
erlend-aasland Mar 5, 2024
fabb007
Fixup run_in_subinterp
erlend-aasland Mar 5, 2024
c51dafa
Fixup test_call
erlend-aasland Mar 5, 2024
c3f9c99
Fixup test_audit
erlend-aasland Mar 5, 2024
fde9548
Fix some _testsinglephase issues
erlend-aasland Mar 5, 2024
ea72ced
Address review: use setUpClass in test_call; don't skip everything
erlend-aasland Mar 5, 2024
628896c
Address review: no need to skip in tearDown
erlend-aasland Mar 5, 2024
88c6739
Address review: check import at the top of test_threading.test_frame_…
erlend-aasland Mar 5, 2024
c02cd6f
Fixup some test.support helpers
erlend-aasland Mar 5, 2024
d49532b
Fixup test_coroutines
erlend-aasland Mar 5, 2024
2427111
Fixup test_threading
erlend-aasland Mar 5, 2024
25d0999
Fixup test_repl
erlend-aasland Mar 5, 2024
bdd8cff
Fixup test_monitoring
erlend-aasland Mar 5, 2024
ee9fa51
Amend test_embed
erlend-aasland Mar 5, 2024
a47c5ff
Amend test_audit
erlend-aasland Mar 5, 2024
d84a5c4
Fix test_socket
erlend-aasland Mar 5, 2024
e877ffb
Resolve test_exceptions nicer
erlend-aasland Mar 5, 2024
1ec0c66
Merge branch 'main' into sqlite/testcapi
erlend-aasland Mar 5, 2024
afa58a9
Use import_helper in test_importlib
erlend-aasland Mar 5, 2024
760c6cb
Fixup test_embed
erlend-aasland Mar 5, 2024
d7f060a
Pull in main
erlend-aasland Mar 5, 2024
a1106b7
Revert spurious docs change
erlend-aasland Mar 5, 2024
db45852
Workaround: use a different test module name in test_module_resources
erlend-aasland Mar 5, 2024
ccd8bea
gh-116307: Create a new import helper 'isolated modules' and use that…
jaraco Mar 6, 2024
f80f75e
Merge branch 'main' into sqlite/testcapi
erlend-aasland Mar 6, 2024
39d135d
Revert "Workaround: use a different test module name in test_module_r…
erlend-aasland Mar 6, 2024
13c4829
Revert another spurious test_importlib change
erlend-aasland Mar 6, 2024
31e19a7
Fix test_embed
erlend-aasland Mar 7, 2024
45e0586
Pull in main
erlend-aasland Mar 7, 2024
a148fb5
Remove useless import from test_embed
erlend-aasland Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Expand Up @@ -508,7 +508,7 @@ def has_no_debug_ranges():
try:
import _testinternalcapi
except ImportError:
raise unittest.SkipTest("_testinternalcapi required")
return unittest.skip("_testinternalcapi required")
config = _testinternalcapi.get_config()
return not bool(config['code_debug_ranges'])
Comment on lines +511 to 513
Copy link
Member

Choose a reason for hiding this comment

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

Why does it return a boolean (which is not callable) or a function (which always true)? How this helper is supposed to be used?


Expand Down
12 changes: 12 additions & 0 deletions Lib/test/support/import_helper.py
Expand Up @@ -268,6 +268,18 @@ def modules_cleanup(oldmodules):
sys.modules.update(oldmodules)


@contextlib.contextmanager
def isolated_modules():
"""
Save modules on entry and cleanup on exit.
"""
(saved,) = modules_setup()
try:
yield
finally:
modules_cleanup(saved)


def mock_register_at_fork(func):
# bpo-30599: Mock os.register_at_fork() when importing the random module,
# since this function doesn't allow to unregister callbacks and would leak
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_embed.py
Expand Up @@ -359,7 +359,6 @@ def test_simple_initialization_api(self):
self.assertEqual(out, 'Finalized\n' * INIT_LOOPS)

@support.requires_specialization
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
# https://github.com/python/cpython/issues/92031

Expand Down Expand Up @@ -1596,7 +1595,6 @@ def test_global_pathconfig(self):
# The global path configuration (_Py_path_config) must be a copy
# of the path configuration of PyInterpreter.config (PyConfig).
ctypes = import_helper.import_module('ctypes')
import _testinternalcapi

def get_func(name):
func = getattr(ctypes.pythonapi, name)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_importlib/extension/test_loader.py
Expand Up @@ -108,7 +108,7 @@ def setUp(self):
)
finder = self.machinery.FileFinder(None)
self.spec = importlib.util.find_spec(self.name)
self.assertIsNotNone(self.spec)
assert self.spec
Copy link
Member

Choose a reason for hiding this comment

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

Why skip this in optimized mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jaraco requested to leave the assert's for importlib tests, so I reverted the unittest assert style changes. The code is shared with an external repo.

Copy link
Member

Choose a reason for hiding this comment

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

FYI - I only care about the retention of bare asserts in the tests for importlib.metadata and importlib.resources. Unfortunately, the tests for importlib.metadata are interspersed with other importlib tests, so it's not easy to know which are which without looking at the cpython branch of importlib_metadata. I do have plans to move importlib.metadata tests into their own package so they're clearly separated.

self.loader = self.machinery.ExtensionFileLoader(
self.name, self.spec.origin)

Expand Down Expand Up @@ -189,7 +189,7 @@ def setUp(self):
)
finder = self.machinery.FileFinder(None)
self.spec = importlib.util.find_spec(self.name)
self.assertIsNotNone(self.spec)
assert self.spec
self.loader = self.machinery.ExtensionFileLoader(
self.name, self.spec.origin)

Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_importlib/resources/test_files.py
Expand Up @@ -70,7 +70,7 @@ def setUp(self):
self.addCleanup(self.fixtures.close)
self.site_dir = self.fixtures.enter_context(os_helper.temp_dir())
self.fixtures.enter_context(import_helper.DirsOnSysPath(self.site_dir))
self.fixtures.enter_context(import_helper.CleanImport())
self.fixtures.enter_context(import_helper.isolated_modules())


class ModulesFilesTests(SiteDir, unittest.TestCase):
Expand All @@ -79,14 +79,14 @@ def test_module_resources(self):
A module can have resources found adjacent to the module.
"""
spec = {
'mod_res.py': '',
'mod.py': '',
'res.txt': 'resources are the best',
}
_path.build(spec, self.site_dir)
import mod_res
import mod

actual = resources.files(mod_res).joinpath('res.txt').read_text(encoding='utf-8')
self.assertEqual(actual, spec['res.txt'])
actual = resources.files(mod).joinpath('res.txt').read_text(encoding='utf-8')
assert actual == spec['res.txt']


class ImplicitContextFilesTests(SiteDir, unittest.TestCase):
Expand Down
@@ -0,0 +1,3 @@
Added import helper ``isolated_modules`` as ``CleanImport`` does not remove
modules imported during the context. Use it in importlib.resources tests to
avoid leaving ``mod`` around to impede importlib.metadata tests.