{"id":27431,"library":"surrogate","title":"surrogate","description":"A Python micro-library to create stubs for non-existing modules, enabling testing of import-dependent code. Current version 0.1, no active development observed.","status":"active","version":"0.1","language":"python","source_language":"en","source_url":"https://github.com/JASchilz/surrogate","tags":["testing","stubs","mock","import"],"install":[{"cmd":"pip install surrogate","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"","wrong":"","symbol":"surrogate","correct":"import surrogate"}],"quickstart":{"code":"import surrogate\n\n# Create a stub for a non-existing module\nsurrogate.replace('mymodule')\n\n# Now you can import it without ImportError\nimport mymodule\n\n# Check that it's indeed a stub\nprint(isinstance(mymodule, surrogate.Surrogate))\n\n# Automatic cleanup on exit","lang":"python","description":"Creates stubs for modules that don't exist, allowing import without error."},"warnings":[{"fix":"Call surrogate.replace('module_name') before any import of that module.","message":"surrogate.replace() must be called before importing the target module, otherwise the real module will be cached.","severity":"gotcha","affected_versions":"all"},{"fix":"If you need attributes, assign them manually after creating the stub.","message":"Stubs are not full mocks; they only prevent ImportError. Attributes accessed on the stub will raise AttributeError unless defined.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure you are using version 0.1 and call surrogate.replace().","cause":"Using an older version of surrogate where the function was named differently.","error":"AttributeError: module 'surrogate' has no attribute 'replace'"},{"fix":"Ensure surrogate.replace() is called before any imports of the module.","cause":"The module was already imported before calling surrogate.replace().","error":"ImportError after surrogate.replace()"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}