pytest-revealtype-injector 0.6.2__tar.gz → 0.6.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/PKG-INFO +3 -3
  2. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/pyproject.toml +3 -5
  3. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/__init__.py +1 -1
  4. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/hooks.py +39 -33
  5. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/.gitignore +0 -0
  6. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/COPYING +0 -0
  7. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/COPYING.mit +0 -0
  8. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/README.md +0 -0
  9. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/adapter/__init__.py +0 -0
  10. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/adapter/basedpyright_.py +0 -0
  11. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/adapter/mypy_.py +0 -0
  12. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/adapter/pyright_.py +0 -0
  13. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/log.py +0 -0
  14. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/main.py +0 -0
  15. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/models.py +0 -0
  16. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/plugin.py +0 -0
  17. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/src/pytest_revealtype_injector/py.typed +0 -0
  18. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/tests/conftest.py +0 -0
  19. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/tests/test_ast_mode.py +0 -0
  20. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/tests/test_import.py +0 -0
  21. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/tests/test_marker.py +0 -0
  22. {pytest_revealtype_injector-0.6.2 → pytest_revealtype_injector-0.6.3}/tests/test_options.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-revealtype-injector
3
- Version: 0.6.2
3
+ Version: 0.6.3
4
4
  Summary: Pytest plugin for replacing reveal_type() calls inside test functions with static and runtime type checking result comparison, for confirming type annotation validity.
5
5
  Project-URL: homepage, https://github.com/abelcheung/pytest-revealtype-injector
6
6
  Author-email: Abel Cheung <abelcheung@gmail.com>
@@ -22,8 +22,8 @@ Classifier: Programming Language :: Python :: 3.14
22
22
  Classifier: Topic :: Software Development :: Testing
23
23
  Classifier: Typing :: Typed
24
24
  Requires-Python: >=3.10
25
- Requires-Dist: pytest<9,>=7.0
26
- Requires-Dist: schema==0.7.7
25
+ Requires-Dist: pytest>=7.0
26
+ Requires-Dist: schema>=0.7.8
27
27
  Requires-Dist: typeguard>=4.3
28
28
  Requires-Dist: typing-extensions>=4.0; python_version < '3.11'
29
29
  Description-Content-Type: text/markdown
@@ -16,10 +16,9 @@ license = 'MIT'
16
16
  license-files = ['COPYING*']
17
17
  dependencies = [
18
18
  'typing_extensions >= 4.0; python_version < "3.11"',
19
- 'pytest >=7.0,<9',
19
+ 'pytest >=7.0',
20
20
  'typeguard >= 4.3',
21
- # schema with annotation support is still unreleased
22
- 'schema == 0.7.7',
21
+ 'schema >= 0.7.8',
23
22
  ]
24
23
  keywords = [
25
24
  'pytest',
@@ -74,13 +73,11 @@ packages = ["src/pytest_revealtype_injector"]
74
73
  typeCheckingMode = 'strict'
75
74
  enableTypeIgnoreComments = false
76
75
  deprecateTypingAliases = true
77
- reportMissingTypeStubs = false
78
76
 
79
77
  [tool.mypy]
80
78
  mypy_path = "$MYPY_CONFIG_FILE_DIR/src"
81
79
  packages = "pytest_revealtype_injector"
82
80
  strict = true
83
- ignore_missing_imports = true
84
81
 
85
82
  [tool.ruff]
86
83
  target-version = "py312"
@@ -128,6 +125,7 @@ pythonpath = [
128
125
  # and never does any permanent change with it
129
126
  [tool.semantic_release]
130
127
  version_variables = ['src/pytest_revealtype_injector/__init__.py:__version__']
128
+ allow_zero_version = true # switch off for 1.0.0
131
129
  major_on_zero = false # switch on for 1.0.0
132
130
 
133
131
  [tool.semantic_release.changelog]
@@ -1,3 +1,3 @@
1
1
  """Pytest plugin for replacing reveal_type() calls inside test functions with static and runtime type checking result comparison, for confirming type annotation validity.""" # noqa: E501
2
2
 
3
- __version__ = "0.6.2"
3
+ __version__ = "0.6.3"
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import functools
4
4
  import inspect
5
+ from collections.abc import Iterator
5
6
  from typing import cast
6
7
 
7
8
  import pytest
@@ -14,7 +15,8 @@ _logger = log.get_logger()
14
15
  adapter_stash_key: pytest.StashKey[set[TypeCheckerAdapter]]
15
16
 
16
17
 
17
- def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> None:
18
+ @pytest.hookimpl(wrapper=True)
19
+ def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> Iterator[None]:
18
20
  assert pyfuncitem.module is not None
19
21
  adp_stash = pyfuncitem.config.stash[adapter_stash_key]
20
22
 
@@ -23,7 +25,7 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> None:
23
25
  if mark:
24
26
  disabled_adapters = {a.id for a in adp_stash if a.id in mark.args}
25
27
  for a in disabled_adapters:
26
- _logger.info(f"{a} adapter disabled by 'notypechecker' marker")
28
+ _logger.info(f"{a} adapter disabled by 'notypechecker' marker in {pyfuncitem.name} test")
27
29
  adapters = {a for a in adp_stash if a.id not in disabled_adapters}
28
30
  else:
29
31
  adapters = {a for a in adp_stash}
@@ -31,39 +33,43 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> None:
31
33
  if not adapters:
32
34
  pytest.fail("All type checkers have been disabled.")
33
35
 
34
- # Replace reveal_type() with our own function
35
- for name in dir(pyfuncitem.module):
36
- if name.startswith("__") or name.startswith("@py"):
37
- continue
38
-
39
- item = getattr(pyfuncitem.module, name)
40
- if inspect.isfunction(item):
41
- if item.__name__ != "reveal_type" or item.__module__ not in {
42
- "typing",
43
- "typing_extensions",
44
- }:
36
+ # Monkeypatch reveal_type() with our own function, to guarantee
37
+ # each test func can receive different adapters
38
+ with pytest.MonkeyPatch.context() as mp:
39
+ for name in dir(pyfuncitem.module):
40
+ if name.startswith("__") or name.startswith("@py"):
45
41
  continue
46
- injected = functools.partial(
47
- revealtype_injector,
48
- adapters=adapters,
49
- rt_funcname=name,
50
- )
51
- setattr(pyfuncitem.module, name, injected)
52
- _logger.info(f"Replaced {name}() from global import with {injected}")
53
- break
54
42
 
55
- elif inspect.ismodule(item):
56
- if item.__name__ not in {"typing", "typing_extensions"}:
57
- continue
58
- assert hasattr(item, "reveal_type")
59
- injected = functools.partial(
60
- revealtype_injector,
61
- adapters=adapters,
62
- rt_funcname=f"{name}.reveal_type",
63
- )
64
- setattr(item, "reveal_type", injected)
65
- _logger.info(f"Replaced {name}.reveal_type() with {injected}")
66
- break
43
+ item = getattr(pyfuncitem.module, name)
44
+ if inspect.isfunction(item):
45
+ if item.__name__ != "reveal_type" or item.__module__ not in {
46
+ "typing",
47
+ "typing_extensions",
48
+ }:
49
+ continue
50
+ injected = functools.partial(
51
+ revealtype_injector,
52
+ adapters=adapters,
53
+ rt_funcname=name,
54
+ )
55
+ mp.setattr(pyfuncitem.module, name, injected)
56
+ _logger.info(f"Replaced {name}() from global import with {injected} in {pyfuncitem.name} test")
57
+ break
58
+
59
+ elif inspect.ismodule(item):
60
+ if item.__name__ not in {"typing", "typing_extensions"}:
61
+ continue
62
+ assert hasattr(item, "reveal_type")
63
+ injected = functools.partial(
64
+ revealtype_injector,
65
+ adapters=adapters,
66
+ rt_funcname=f"{name}.reveal_type",
67
+ )
68
+ mp.setattr(item, "reveal_type", injected)
69
+ _logger.info(f"Replaced {name}.reveal_type() with {injected} in {pyfuncitem.name} test")
70
+ break
71
+
72
+ return cast(None, (yield)) # type: ignore[redundant-cast]
67
73
 
68
74
 
69
75
  def pytest_collection_finish(session: pytest.Session) -> None: