Skip to content

Test isolation of active locales between threads - #493

Open
Alex-ardashev wants to merge 1 commit into
python-humanize:mainfrom
Alex-ardashev:test/thread-local-translations
Open

Alex-ardashev wants to merge 1 commit into
python-humanize:mainfrom
Alex-ardashev:test/thread-local-translations

Conversation

@Alex-ardashev

Copy link
Copy Markdown

Add a synchronized two-thread test for locale isolation. It checks that a new thread starts in the default locale, activating French does not change the main thread's German locale, and deactivation in the main thread does not reset the worker's French locale.

The test checks translation selection and formatted numbers. It uses cached translation objects so it does not need compiled catalogs. Events have bounded waits, and both threads restore their default locale.

Validation on macOS, Python 3.12.5:

  • tox -e py -- --benchmark-disable: 879 passed, with compiled catalogs. Local pytest was set to 9.1.1 because 9.2.0 raises an unrelated _nodeid error in the existing benchmark fixture.
  • tox -e mypy and prek run --files tests/test_i18n.py: passed.
  • Replacing thread-local state with shared state in a separate test process makes the new test fail.

This change adds test coverage; it does not change runtime behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant