+
Skip to content

Incompatible with mypy #184

@phillipuniverse

Description

@phillipuniverse

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:

Image

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:

# 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载