1010
1111import pytest
1212
13- import attrs
14-
1513
1614pytestmark = [
1715 pytest .mark .skipif (
2018]
2119
2220
23- @attrs .frozen
24- class PyrightDiagnostic :
25- severity : str
26- message : str
27-
28-
29- def parse_pyright_output (test_file : Path ) -> set [PyrightDiagnostic ]:
21+ def parse_pyright_output (test_file : Path ) -> set [tuple [str , str ]]:
3022 pyright = subprocess .run ( # noqa: PLW1510
3123 ["pyright" , "--outputjson" , str (test_file )], capture_output = True
3224 )
3325
3426 pyright_result = json .loads (pyright .stdout )
3527
28+ # We use tuples instead of proper classes to get nicer diffs from pytest.
3629 return {
37- PyrightDiagnostic (d ["severity" ], d ["message" ])
30+ (d ["severity" ], d ["message" ])
3831 for d in pyright_result ["generalDiagnostics" ]
3932 }
4033
@@ -49,41 +42,40 @@ def test_pyright_baseline():
4942
5043 diagnostics = parse_pyright_output (test_file )
5144
52- # Expected diagnostics as per pyright 1.1.311
5345 expected_diagnostics = {
54- PyrightDiagnostic (
55- severity = "information" ,
56- message = 'Type of "Define.__init__" is'
57- ' "(self: Define, a: str, b: int) -> None"' ,
46+ (
47+ "information" ,
48+ 'Type of "Define.__init__" is "(self: Define, a: str, b: int) -> None"' ,
5849 ),
59- PyrightDiagnostic (
60- severity = "information" ,
61- message = 'Type of "DefineConverter.__init__" is '
50+ (
51+ "information" ,
52+ 'Type of "DefineConverter.__init__" is '
6253 '"(self: DefineConverter, with_converter: str | Buffer | '
6354 'SupportsInt | SupportsIndex | SupportsTrunc) -> None"' ,
6455 ),
65- PyrightDiagnostic (
66- severity = "error" ,
67- message = 'Cannot assign member "a" for type '
68- '"Frozen"\n \xa0 \xa0 "Frozen" is frozen\n \xa0 \xa0 \xa0 \xa0 Member "__set__" is unknown' ,
56+ (
57+ "error" ,
58+ 'Cannot assign to attribute "a" for class '
59+ '"Frozen"\n \xa0 \xa0 "Frozen" is frozen\n \xa0 \xa0 \xa0 \xa0 '
60+ 'Attribute "__set__" is unknown' ,
6961 ),
70- PyrightDiagnostic (
71- severity = "information" ,
72- message = 'Type of "d.a" is "Literal[\' new\' ]"' ,
62+ (
63+ "information" ,
64+ 'Type of "d.a" is "Literal[\' new\' ]"' ,
7365 ),
74- PyrightDiagnostic (
75- severity = "error" ,
76- message = 'Cannot assign member "a" for type '
66+ (
67+ "error" ,
68+ 'Cannot assign to attribute "a" for class '
7769 '"FrozenDefine"\n \xa0 \xa0 "FrozenDefine" is frozen\n \xa0 \xa0 \xa0 \xa0 '
78- 'Member "__set__" is unknown' ,
70+ 'Attribute "__set__" is unknown' ,
7971 ),
80- PyrightDiagnostic (
81- severity = "information" ,
82- message = 'Type of "d2.a" is "Literal[\' new\' ]"' ,
72+ (
73+ "information" ,
74+ 'Type of "d2.a" is "Literal[\' new\' ]"' ,
8375 ),
84- PyrightDiagnostic (
85- severity = "information" ,
86- message = 'Type of "af.__init__" is "(_a: int) -> None"' ,
76+ (
77+ "information" ,
78+ 'Type of "af.__init__" is "(_a: int) -> None"' ,
8779 ),
8880 }
8981
@@ -110,9 +102,9 @@ def test_pyright_attrsinstance_compat(tmp_path):
110102
111103 diagnostics = parse_pyright_output (test_pyright_attrsinstance_compat_path )
112104 expected_diagnostics = {
113- PyrightDiagnostic (
114- severity = "information" ,
115- message = 'Type of "attrs.AttrsInstance" is "type[AttrsInstance]"' ,
116- ),
105+ (
106+ "information" ,
107+ 'Type of "attrs.AttrsInstance" is "type[AttrsInstance]"' ,
108+ )
117109 }
118110 assert diagnostics == expected_diagnostics
0 commit comments