Pytest helpers and viur-core stand-ins for testing ViUR packages without App Engine.
Project description
viur-light-mock
Pytest helpers and viur.core.* stand-ins for testing ViUR packages without
App Engine.
What it does
viur-light-mock is a pytest plugin that injects lightweight stand-ins for the
viur.core.* modules into sys.modules before your tests are collected.
That lets a package import from viur.core import db, utils, errors, … in
production code while the tests run hermetically — no Google App Engine
stack, no Datastore connection, fast cold-start.
The plugin auto-discovers via the pytest11 entry-point. No conftest.py
boilerplate, no pytest_plugins = line — install the package and the
fixtures and mocks are there.
Requirements
- Python ≥ 3.12
- pytest ≥ 8
Install
The PyPI distribution name is spltz-viur-light-mock (the
experimental spltz- prefix marks it pre-1.0). The Python import
path stays viur.light_mock — namespace package, no rename in user
code.
pip install spltz-viur-light-mock
For a ViUR-based package that wants to use it:
[project.optional-dependencies]
test = ["pytest", "pytest-cov", "spltz-viur-light-mock>=0.1"]
Usage
Just write tests as if viur.core were real:
# tests/test_my_module.py
def test_something(db_state, freeze_time, make_query):
from viur.core.db import Entity, Key
from my_package import MyAdapter
existing = Entity(Key("order_revision", 1))
existing["revision_index"] = 7
make_query(single=existing)
MyAdapter().do_something()
assert any(p["revision_index"] == 8 for p in db_state.put_calls)
The fixtures used here (db_state, freeze_time, make_query) are
auto-discovered from the plugin — you don't need to import them or wire
them up in a conftest.py.
What's mocked
| Module | Stand-in surface |
|---|---|
viur.core |
Plus identity decorators exposed, force_post, skey |
viur.core.db |
Key, Entity, Query, SortOrder, Get, Put, Delete, AllocateIDs |
viur.core.utils |
utcNow() — freezable |
viur.core.errors |
Unauthorized, Forbidden, BadRequest, NotFound |
viur.core.current |
user, request slots with .get/.set |
viur.core.skeleton |
Skeleton, SkeletonInstance, DatabaseAdapter |
viur.core.tasks |
PeriodicTask decorator (no-op, but tags the wrapped function) |
viur.core.render.json.default |
CustomJsonEncoder aliased to stdlib json.JSONEncoder |
Fixtures
| Fixture | Purpose |
|---|---|
db_state |
Handle on the in-memory datastore (store, put_calls, delete_calls, …) |
freeze_time |
Pin utils.utcNow() to a controllable value |
make_query |
Pre-populate the next db.Query(...) with single/many results |
patched_user |
Set current.user.get() to a fake user dict |
_viur_light_mock_reset_state |
Autouse — resets the fake datastore singleton between tests |
Public API
If you need to drive the mocks from your own conftest.py (for example to
add a project-specific stand-in), import directly:
from viur.light_mock import (
install_viur_core_mocks,
FakeKey, FakeEntity, FakeQuery, FakeSortOrder, DbState,
)
Why not just use unittest.mock?
You can — but the fake viur.core modules here are real Python modules
in sys.modules, so from viur.core import db resolves naturally without
patching every test, and isinstance checks against db.Entity etc. work
out of the box.
Development
git clone https://github.com/sprengplatz/viur-light-mock
cd viur-light-mock
pip install -e ".[dev]"
pytest # 100% coverage required
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spltz_viur_light_mock-0.1.0.tar.gz.
File metadata
- Download URL: spltz_viur_light_mock-0.1.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf85133f9278e7351d09ffeaef7f4f1b327e0a6381662f0125e59adba4f583f0
|
|
| MD5 |
6c5ed44041c2d59a229fe47fa58ebe9b
|
|
| BLAKE2b-256 |
4a4c831a47e8f44f364e0a8772a39d30c46b27ebb06573173fb1f0f5a1500781
|
Provenance
The following attestation bundles were made for spltz_viur_light_mock-0.1.0.tar.gz:
Publisher:
release.yml on sprengplatz/viur-light-mock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spltz_viur_light_mock-0.1.0.tar.gz -
Subject digest:
cf85133f9278e7351d09ffeaef7f4f1b327e0a6381662f0125e59adba4f583f0 - Sigstore transparency entry: 1639086666
- Sigstore integration time:
-
Permalink:
sprengplatz/viur-light-mock@032020147c55690221971eda48b91e2551444509 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sprengplatz
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@032020147c55690221971eda48b91e2551444509 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spltz_viur_light_mock-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spltz_viur_light_mock-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17580b8af6695b3ba2c7640380e19fd0e820176fa942faf52f35b5e4d86898f2
|
|
| MD5 |
f654afe959bf1f13c645d0f6ff1d8292
|
|
| BLAKE2b-256 |
e411570b80a5121247d03d7b9263837d02188b064b43f3519c45b4532891d20e
|
Provenance
The following attestation bundles were made for spltz_viur_light_mock-0.1.0-py3-none-any.whl:
Publisher:
release.yml on sprengplatz/viur-light-mock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spltz_viur_light_mock-0.1.0-py3-none-any.whl -
Subject digest:
17580b8af6695b3ba2c7640380e19fd0e820176fa942faf52f35b5e4d86898f2 - Sigstore transparency entry: 1639086804
- Sigstore integration time:
-
Permalink:
sprengplatz/viur-light-mock@032020147c55690221971eda48b91e2551444509 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sprengplatz
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@032020147c55690221971eda48b91e2551444509 -
Trigger Event:
push
-
Statement type: