Skip to content

Singleton override context manager (3pt) #73

Description

@henry0816191

Problem

The module-level settings = Settings() singleton in src/paperscout/config.py is instantiated at import time. Tests work around this by setting _PAPERSCOUT_TESTING=1 before import. There is no supported mechanism to temporarily override the global singleton for integration scenarios or fixture-driven parametric tests.

Acceptance Criteria

  • A context manager (e.g., override_settings(**kwargs)) temporarily replaces the module-level settings singleton and restores it on exit
  • The context manager handles exceptions and re-raises after cleanup
  • Existing test code can use the context manager instead of env-var manipulation
  • The override is documented as the supported test-override mechanism

Implementation Notes

  • Primary file: src/paperscout/config.py — add override_settings() context manager
  • Pattern: contextlib.contextmanager that swaps and restores paperscout.config.settings
  • Test fixture update: tests/conftest.py — optionally refactor make_test_settings()

References

  • src/paperscout/config.py (settings = Settings())
  • tests/conftest.py (os.environ.setdefault("_PAPERSCOUT_TESTING", "1"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions