Skip to content

Commit 488f994

Browse files
committed
use pytest_mypy_plugins to test mypy plugin
1 parent c65fe84 commit 488f994

File tree

3 files changed

+30
-89
lines changed

3 files changed

+30
-89
lines changed

setup.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"docs": ["sphinx"],
2121
"tests": [
2222
"pytest",
23-
# typed-ast (a dependency of mypy) fails to install on pypy
23+
# re: pypy: typed-ast (a dependency of mypy) fails to install on pypy
2424
# https://github.com/python/typed_ast/issues/111
25-
"mypy; implementation_name != 'pypy'",
25+
# re: win32: pytest-mypy-plugins depends on capturer, which isn't supported on
26+
# windows
27+
"pytest-mypy-plugins; implementation_name != 'pypy' and sys.platform != 'win32'",
2628
],
2729
}
2830
EXTRAS_REQUIRE["dev"] = (

tests/test_mypy.py

-87
This file was deleted.

tests/test_mypy.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Tests for marshmallow_dataclass.mypy, using pytest-mypy-plugins
2+
# NOTE: Since pytest-mypy-plugins is not installed on pypy (see setup.py), these tests
3+
# will not even be collected by pytest
4+
- case: NewType_basic
5+
mypy_config: |
6+
follow_imports = silent
7+
plugins = marshmallow_dataclass.mypy
8+
main: |
9+
from dataclasses import dataclass
10+
import marshmallow as ma
11+
from marshmallow_dataclass import NewType
12+
13+
Email = NewType("Email", str, validate=ma.validate.Email)
14+
UserID = NewType("UserID", validate=ma.validate.Length(equal=32), typ=str)
15+
16+
@dataclass
17+
class User:
18+
id: UserID
19+
email: Email
20+
21+
user = User(id="a"*32, email="[email protected]")
22+
reveal_type(user.id) # N: Revealed type is 'builtins.str'
23+
reveal_type(user.email) # N: Revealed type is 'builtins.str'
24+
25+
User(id=42, email="[email protected]") # E: Argument "id" to "User" has incompatible type "int"; expected "str"
26+
User(id="a"*32, email=["not", "a", "string"]) # E: Argument "email" to "User" has incompatible type "List[str]"; expected "str"

0 commit comments

Comments
 (0)