-
-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Hello, thanks for the great project!
I've got a very simple example that doesn't work with mypy:
from pytest_check.context_manager import CheckContextManager
def test_something(check: CheckContextManager) -> None:
check.equal(1, 2, "oops")
Running this code with mypy strict=true
yields:
tests/__init__.py:5: error: "CheckContextManager" has no attribute "equal" [attr-defined]
check.equal(1, 2, "oops")
Pycharm also complains:
This was originally reported in #175 regarding pylint, this is a slightly different context with mypy.
This is caused by the dynamic nature of adding in attributes to the CheckContextManager
instance:
pytest-check/src/pytest_check/__init__.py
Lines 30 to 49 in 6bf2b22
# allow check.raises() | |
setattr(check, "raises", raises) | |
# allow check.any_failures() | |
setattr(check, "any_failures", any_failures) | |
# allow check.check as a context manager. | |
# weird, but some people are doing it. | |
# deprecate this eventually | |
setattr(check, "check", check) | |
# allow for helper functions to be part of check context | |
# manager and check fixture: | |
# from pytest_check import check | |
# def test_(): | |
# check.equal(1, 1) | |
# with check: | |
# assert 1 == 2 | |
for func in check_functions.__all__: # noqa: F405 | |
setattr(check, func, getattr(check_functions, func)) # noqa: F405 |
I can see why you might want to do this dynamically and not have the source of truth be on ContextManager
instance, but would you consider adding a context_manager.pyi
type stub that denotes these functions do in fact get added to ContextManager
? I believe that's the solution for this problem.