{"id":22301975,"url":"https://github.com/abelcheung/pytest-revealtype-injector","last_synced_at":"2025-07-29T03:32:46.268Z","repository":{"id":265128282,"uuid":"895214125","full_name":"abelcheung/pytest-revealtype-injector","owner":"abelcheung","description":"Pytest plugin for replacing reveal_type() calls with static and runtime type checking result comparison","archived":false,"fork":false,"pushed_at":"2024-11-27T19:55:36.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-27T20:29:16.158Z","etag":null,"topics":["annotation","dynamic-typing","pytest-plugin","runtime-typechecking","static-typing","type-check","type-checker","type-checking","typecheck","typechecker","typechecking","types","typing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abelcheung.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-27T19:14:50.000Z","updated_at":"2024-11-27T19:55:38.000Z","dependencies_parsed_at":"2024-11-27T20:40:41.135Z","dependency_job_id":null,"html_url":"https://github.com/abelcheung/pytest-revealtype-injector","commit_stats":null,"previous_names":["abelcheung/pytest-revealtype-injector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelcheung%2Fpytest-revealtype-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelcheung%2Fpytest-revealtype-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelcheung%2Fpytest-revealtype-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelcheung%2Fpytest-revealtype-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abelcheung","download_url":"https://codeload.github.com/abelcheung/pytest-revealtype-injector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227961451,"owners_count":17847830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation","dynamic-typing","pytest-plugin","runtime-typechecking","static-typing","type-check","type-checker","type-checking","typecheck","typechecker","typechecking","types","typing"],"created_at":"2024-12-03T18:33:14.940Z","updated_at":"2025-07-29T03:32:46.241Z","avatar_url":"https://github.com/abelcheung.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![PyPI - Version](https://img.shields.io/pypi/v/pytest-revealtype-injector)\n![GitHub Release Date](https://img.shields.io/github/release-date/abelcheung/pytest-revealtype-injector)\n![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fgithub.com%2Fabelcheung%2Fpytest-revealtype-injector%2Fraw%2Frefs%2Fheads%2Fmain%2Fpyproject.toml)\n![PyPI - Wheel](https://img.shields.io/pypi/wheel/pytest-revealtype-injector)\n\n`pytest-revealtype-injector` is a `pytest` plugin for replacing [`reveal_type()`](https://docs.python.org/3/library/typing.html#typing.reveal_type) calls inside test functions as something more sophisticated. It does the following tasks in parallel:\n\n- Launch external static type checkers (`basesdpyright`, `pyright` and `mypy`) and store `reveal_type` results.\n- Use [`typeguard`](https://github.com/agronholm/typeguard) to verify the aforementioned static type checker result _really_ matches runtime code result.\n\n## Usage\n\nIn short: install this plugin, create test functions which calls `reveal_type()` with variable or function return result, done.\n\n### The longer story\n\nThis plugin would be automatically enabled when launching `pytest`.\n\nFor using `reveal_type()` inside tests, there is no boiler plate code involved. Import `reveal_type` normally, like:\n\n```python\nfrom typing import reveal_type\n```\n\nIf you care about compatibility with older pythons, use:\n\n```python\nimport sys\nif sys.version \u003e= (3, 11):\n    from typing import reveal_type\nelse:\n    from typing_extensions import reveal_type\n```\n\nJust importing `typing` (or `typing_extensions`) module is fine too:\n\n```python\nimport typing\n\ndef test_something():\n    x: str = 1  # type: ignore  # pyright: ignore\n    typing.reveal_type(x)  # typeguard fails here\n```\n\nSince this plugin scans for `reveal_type()` for replacement under carpet, even `import ... as ...` syntax works:\n\n```python\nimport typing as typ  # or...\nfrom typing import reveal_type as rt\n```\n\n### Limitations\n\nBut there are 2 caveats.\n\n1. This plugin only searches for global import in test files, so local import inside test function doesn't work. That means following code doesn't utilize this plugin at all:\n\n```python\ndef test_something():\n    from typing import reveal_type\n    x = 1\n    reveal_type(x)  # calls vanilla reveal_type()\n```\n\n2. `reveal_type()` calls have to stay within a single line, although you can use `reveal_type` result in assertion or other purpose:\n\n```python\nx = \"1\"\nassert reveal_type(str(int(x))) == x\n```\n\n## Disable type checker with marker\n\nUsing [pytest marker](https://docs.pytest.org/en/stable/example/markers.html), it is possible to disable usage of certain type checker for specific test. All 3 types of markers (function, class and module level) are supported.\n\nFunction level:\n```python\n@pytest.mark.notypechecker(\"mypy\")\ndef test_something(self) -\u003e None:\n    x = 1\n    reveal_type(x)\n```\n\nClass level:\n```python\n@pytest.mark.notypechecker(\"pyright\")\nclass TestSomething:\n    def test_foo(self) -\u003e None:\n    ...\n```\n\nModule level:\n```python\npytestmark = pytest.mark.notypechecker(\"basedpyright\", \"pyright\")\n```\n\nNote that disabling all type checkers is disallowed, and such tests would be treated as `pytest.fail`. Disable the `reveal_type()` call instead.\n\n## Logging\n\nThis plugin uses standard [`logging`](https://docs.python.org/3/library/logging.html) internally. `pytest -v` can be used to reveal `INFO` and `DEBUG` logs. Given following example:\n\n```python\ndef test_superfluous(self) -\u003e None:\n    x: list[str] = ['a', 'b', 'c', 1]  # type: ignore  # pyright: ignore\n    reveal_type(x)\n```\n\nSomething like this will be shown as test result:\n\n```\n...\n    raise TypeCheckError(f\"is not an instance of {qualified_name(origin_type)}\")\nE   typeguard.TypeCheckError: item 3 is not an instance of str (from pyright)\n------------------------------------------------------------- Captured log call -------------------------------------------------------------\nINFO     revealtype-injector:hooks.py:26 Replaced reveal_type() from global import with \u003cfunction revealtype_injector at 0x00000238DB923D00\u003e\nDEBUG    revealtype-injector:main.py:60 Extraction OK: code='reveal_type(x)', result='x'\n========================================================== short test summary info ==========================================================\nFAILED tests/runtime/test_attrib.py::TestAttrib::test_superfluous - typeguard.TypeCheckError: item 3 is not an instance of str (from pyright)\n============================================================= 1 failed in 3.38s =============================================================\n```\n\n\n## History\n\nThis pytest plugin starts its life as part of testsuite related utilities within [`types-lxml`](https://github.com/abelcheung/types-lxml). As `lxml` is a `cython` project and probably never incorporate inline python annotation in future, there is need to compare runtime result to static type checker output for discrepancy. As time goes by, it starts to make sense to manage as an independent project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabelcheung%2Fpytest-revealtype-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabelcheung%2Fpytest-revealtype-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabelcheung%2Fpytest-revealtype-injector/lists"}