Install and migrate
Install
pip install sg-mockgun
Requires Python 3.9 or later. shotgun-api3 3.10.5 or later is the only dependency.
Start a mock site
from sg_mockgun import Shotgun, schemas
Shotgun.set_schema_paths(*schemas.paths())
sg = Shotgun("https://mock.example.com", script_name="x", api_key="y")
schemas.paths() returns the bundled Flow PT 8.91 schema. schemas.paths("upstream_3_10_5") returns the test schema from shotgun_api3 3.10.5. See What is modelled.
Migrate from shotgun_api3's mockgun
Replace the import:
# from shotgun_api3.lib import mockgun
import sg_mockgun as mockgun
The package exports Shotgun, generate_schema, MockgunError and the submodules mockgun, schema and errors, as upstream does. The constructor signature is upstream's.
Differences from upstream
ShotgunandMockgunErrorare new classes. Amock.patchtarget or anexceptclause namingshotgun_api3.lib.mockgunmisses them.set_schema_pathsis per class. Calling it on upstream'sShotgundoes not configure sg-mockgun's.- The event log is on by default. Set
sg.generate_event_log_entries = Falseto turn it off. schema_field_create,schema_field_updateandschema_field_deletewrite to the schema instead of raisingNotImplementedError.- Each instance deep-copies the schema. A schema write on one instance does not reach another.
from sg_mockgun import mockgunreturns the submodule, which has nogenerate_schema.- A refused filter or write raises
shotgun_api3.Faultwith the site's wording where an api3 answer is recorded. Upstream raisedShotgunErroror accepted the value. - A create without
projecton a Shot, Version, Asset, Sequence, Task, Playlist, PublishedFile, Note or Delivery is refused. Setsg.require_project = Falseto skip the check.
Site values
sg.set_info(**values)changes keys of the payloadinfo(),server_infoandserver_capsread.server_infoandserver_capstake an assigned value, as upstream mockgun's callers assign them.server_capsfollows an assignedserver_info.- A naive
datetimein a write or a filter is local time, as the client sends it. sg.set_clock(fn)makes timestamps deterministic.- A mock instance pickles.