Registry / testing / surrogate

surrogate

JSON →
library0.1pypypi✓ verified 90d ago

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.

pip install surrogate
INSTALL
IMPORT
SIG · SURROGATE
S
surrogate
testingpythonv0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

surrogate
✓ import surrogate

Creates stubs for modules that don't exist, allowing import without error.

import surrogate # Create a stub for a non-existing module surrogate.replace('mymodule') # Now you can import it without ImportError import mymodule # Check that it's indeed a stub print(isinstance(mymodule, surrogate.Surrogate)) # Automatic cleanup on exit
Debug
Known issues
gotchasurrogate.replace() must be called before importing the target module, otherwise the real module will be cached.
fix
Call surrogate.replace('module_name') before any import of that module.
affects: all
gotchaStubs are not full mocks; they only prevent ImportError. Attributes accessed on the stub will raise AttributeError unless defined.
fix
If you need attributes, assign them manually after creating the stub.
affects: all
Errors
Common errors & fixes
AttributeError: module 'surrogate' has no attribute 'replace'
Using an older version of surrogate where the function was named differently.
fix
Ensure you are using version 0.1 and call surrogate.replace().
ImportError after surrogate.replace()
The module was already imported before calling surrogate.replace().
fix
Ensure surrogate.replace() is called before any imports of the module.
Upgrade
Version history
0.1latest on PyPI · released Apr 11, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
surrogate — pip install surrogate · libregistry