{"id":21811,"library":"pytest-schema","title":"pytest-schema","description":"A pytest plugin that allows you to validate return values against a schema-like object, built on top of the `schema` library. Current version 0.1.2, released June 2024. Low release cadence.","status":"active","version":"0.1.2","language":"python","source_language":"en","source_url":"https://github.com/codedawi/pytest-schema","tags":["pytest","testing","schema validation","assertion"],"install":[{"cmd":"pip install pytest-schema","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core testing framework","package":"pytest","optional":false},{"reason":"Schema validation library","package":"schema","optional":false}],"imports":[{"note":"Direct import from pytest_schema","wrong":"","symbol":"schema","correct":"from pytest_schema import schema"},{"note":"Alias for like method","wrong":"","symbol":"like_schema","correct":"from pytest_schema import like_schema"},{"note":"Alias for exact method","wrong":"","symbol":"exact_schema","correct":"from pytest_schema import exact_schema"}],"quickstart":{"code":"from pytest_schema import schema\n\ndef test_validate_schema():\n    expected = {\"name\": str, \"age\": int}\n    actual = {\"name\": \"Alice\", \"age\": 30}\n    assert actual == schema(expected)\n\ndef test_like_schema():\n    from pytest_schema import like_schema\n    expected = {\"id\": int, \"value\": str}\n    actual = {\"id\": 1, \"value\": \"foo\", \"extra\": True}\n    assert actual == like_schema(expected)\n\ndef test_exact_schema():\n    from pytest_schema import exact_schema\n    expected = {\"key\": str}\n    actual = {\"key\": \"val\"}\n    assert actual == exact_schema(expected)","lang":"python","description":"Basic usage of schema, like_schema, and exact_schema in pytest tests."},"warnings":[{"fix":"Always use `assert actual == schema(expected)` or `assert actual != schema(expected)`.","message":"The `schema` callable returns a validator that must be compared with `==` (or `!=`) to actually validate. Simply calling `schema(...)` without comparison does nothing.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `like_schema` when extra keys are acceptable; use `exact_schema` when the dict must match exactly.","message":"`like_schema` (or `like`) allows extra keys in the actual dict, while `exact_schema` (or `exact`) does not. Using the wrong one can cause false passes or failures.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `like_schema` and `exact_schema` instead.","message":"The methods `like` and `exact` are deprecated in favor of `like_schema` and `exact_schema`. The old names may be removed in future versions.","severity":"deprecated","affected_versions":">=0.1.1"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `pip install pytest-schema` in your virtual environment.","cause":"pytest-schema is not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'pytest_schema'"},{"fix":"Import `schema` from `pytest_schema` instead: `from pytest_schema import schema`.","cause":"Using the `schema` object from `schema` library directly instead of pytest_schema's wrapper.","error":"TypeError: 'Schema' object is not callable"},{"fix":"Check the types and structure of your actual data against the schema definition.","cause":"The schema comparison failed because the actual data does not match the schema.","error":"AssertionError: assert <pytest_schema...> == ..."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}