python / python/cpython

test.test_zoneinfo.test_zoneinfo.ExtensionBuiltTest.test_cache_location fails if `_zoneinfo` Cextension isn't built

Open
#120,965 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules tests type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

I was doing some testing to check that Python without optional C extensions remains functional, and I've noticed that the following test fails if _zoneinfo is not built:

======================================================================
FAIL: test_cache_location (test.test_zoneinfo.test_zoneinfo.ExtensionBuiltTest.test_cache_location)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mgorny/git/cpython/Lib/test/test_zoneinfo/test_zoneinfo.py", line 1931, in test_cache_location
    self.assertFalse(hasattr(c_zoneinfo.ZoneInfo, "_weak_cache"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: True is not false

FWICS the zoneinfo module tests unconditionally assume that zoneinfoimported with no "blocked" modules. While most of the time, this shouldn't matter, I suppose it would be cleaner to haveget_modules()returnNoneasc_moduleif_zoneinfo` is not importable.

I can try making a PR for this if you agree with this approach (and skipping the duplicate-then C extension tests).

CC @pganssle

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-131104

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Lib/test/test_zoneinfo/test_zoneinfo.py at ExtensionBuiltTest.test_cache_location and inspect get_modules(), especially how it handles an unavailable _zoneinfo module. Verify the zoneinfo tests when the optional C extension is not built, including whether duplicate C-extension tests are skipped. Done means the test suite no longer assumes _zoneinfo is importable and the reported failure is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.