Skip to main content

PyPI - Version GitHub Release Date Python Version from PEP 621 TOML PyPI - Wheel

pytest-revealtype-injector is a pytest plugin for replacing reveal_type() calls inside test functions as something more sophisticated. It does the following tasks in parallel:

  • Launch external static type checkers and store reveal_type results.
  • Use typeguard to verify the aforementioned static type checker result really matches runtime code result.

Usage

TL;DR:

  1. Install this plugin
  2. Install type checkers: basedpyright, mypy, pyrefly, pyright, ty
    • Disable any unwanted with --revealtype-disable-adapter=<ADAPTER> pytest CLI option
  3. Create pytest functions which call reveal_type() with variable or function return result

The longer story

This plugin would be automatically enabled when launching pytest.

For using reveal_type() inside tests, there is no boiler plate code involved. Import reveal_type normally, like:

from typing import reveal_type

If you care about compatibility with older pythons, use:

import sys
if sys.version >= (3, 11):
    from typing import reveal_type
else:
    from typing_extensions import reveal_type

Just importing typing (or typing_extensions) module is fine too:

import typing

def test_something():
    x: str = 1  # type: ignore  # pyright: ignore
    typing.reveal_type(x)  # typeguard fails here

Since this plugin scans for reveal_type() for replacement under carpet, even import ... as ... syntax works:

import typing as typ  # or...
from typing import reveal_type as rt

To supply config file specific for certain type checker, use --revealtype-<ADAPTER>-config=<FILE> pytest CLI option. For example, --revealtype-pyrefly-config=tests/pyrefly.toml instructs pyrefly to use pyrefly.toml under tests folder to override project root config.

Limitations

There are 3 caveats.

  1. 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:
def test_something():
    from typing import reveal_type
    x = 1
    reveal_type(x)  # calls vanilla reveal_type()
  1. reveal_type() calls have to stay within a single line, although you can use reveal_type result in assertion or other purpose:
x = "1"
assert reveal_type(str(int(x))) == x
  1. This plugin does not enlist any type checker as dependency, because any of them can be optionally disabled with pytest marker (see below) or command line option. It is up to application or library authors to include suitable type checker(s) as dependency themselves.

Disable type checker with marker

Using pytest marker, 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.

Function level:

@pytest.mark.notypechecker("mypy")
def test_something(self) -> None:
    x = 1
    reveal_type(x)

Class level:

@pytest.mark.notypechecker("pyright")
class TestSomething:
    def test_foo(self) -> None:
    ...

Module level:

pytestmark = pytest.mark.notypechecker("basedpyright", "pyright")

Conversely, it is possible to only turn on usage of specific type checkers with onlytypechecker marker and exclude all others:

@pytest.mark.onlytypechecker("mypy")
def test_for_mypy() -> None:
    ......

Note that disabling all type checkers is disallowed, and such tests would be treated as failure. Disable the reveal_type() call instead.

Logging

This plugin uses standard logging internally. pytest -v can be used to reveal INFO and DEBUG logs. Given following example:

def test_superfluous(self) -> None:
    x: list[str] = ['a', 'b', 'c', 1]  # type: ignore  # pyright: ignore
    reveal_type(x)

Something like this will be shown as test result:

...
    raise TypeCheckError(f"is not an instance of {qualified_name(origin_type)}")
E   typeguard.TypeCheckError: item 3 is not an instance of str (from pyright)
------------------------------------------------------------- Captured log call -------------------------------------------------------------
INFO     revealtype-injector:hooks.py:26 Replaced reveal_type() from global import with <function revealtype_injector at 0x00000238DB923D00>
DEBUG    revealtype-injector:main.py:60 Extraction OK: code='reveal_type(x)', result='x'
========================================================== short test summary info ==========================================================
FAILED tests/runtime/test_attrib.py::TestAttrib::test_superfluous - typeguard.TypeCheckError: item 3 is not an instance of str (from pyright)
============================================================= 1 failed in 3.38s =============================================================

History

This pytest plugin starts its life as part of testsuite related utilities within 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.

License-wise, originally it was part of types-lxml project, which is released under Apache-2.0 license. But as the sole author, it is at my own discretion to follow pytest license (which is MIT) because this project is taking shape as a pytest plugin.

Metadata

Release files for pytest-revealtype-injector 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-revealtype-injector 0.9.0
File Size Uploaded
pytest_revealtype_injector-0.9.0.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-revealtype-injector 0.9.0
File Interpreter ABI Platform
pytest_revealtype_injector-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.4 kB

Release files / pytest_revealtype_injector-0.9.0.tar.gz

Download URL pytest_revealtype_injector-0.9.0.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f8ab92072bbdd8aedb91d69399e7faaab8e1cd4bc229cbaa2fb3b571fb9b2ae4
BLAKE2b-256 checksum
How to use checksums
5b9b3660554e94b70e879de2b89e92db074833f06ed42aba635d3b40cad7de89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 3, 2026.

Transparency log

Release files / pytest_revealtype_injector-0.9.0-py3-none-any.whl

Download URL pytest_revealtype_injector-0.9.0-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c14f62b4a24d78edebec49308fec6fc0ff3b55a08f94a2889b3ab7d551e8cf6
BLAKE2b-256 checksum
How to use checksums
19e4f4361c137adf9e11ad37a5def73194b57d1c31fba726ce1278f3ee97a7ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page