Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkutaj/16e94be79b89f67d14d906d4a59405bd to your computer and use it in GitHub Desktop.
Save pkutaj/16e94be79b89f67d14d906d4a59405bd to your computer and use it in GitHub Desktop.
2023-07-17-How-to-Create-Dummy-Context-Manager-for-Python-Unit-Tests.md
Code Explanation
from contextlib import nullcontext Import the nullcontext context manager from the contextlib module.
monkeypatch.setattr(schema_patcher, "handle_patching", lambda _: nullcontext()) Replace the handle_patching function with a lambda function that returns a nullcontext object.
with push_and_pop_path(MODULE_PATH): schema_patcher.patch_schema(iglu) Call the patch_schema function within a with statement that uses the push_and_pop_path context manager.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment