@@ -58,12 +58,6 @@ def __init__(
58
58
pass
59
59
60
60
self ._test_file = test_file
61
- self ._check_end_position = (
62
- sys .version_info >= self ._test_file .options ["min_pyver_end_position" ]
63
- )
64
- # TODO: PY3.9: PyPy supports end_lineno from 3.9 and above
65
- if self ._check_end_position and IS_PYPY :
66
- self ._check_end_position = sys .version_info >= (3 , 9 ) # pragma: no cover
67
61
try :
68
62
args = [test_file .source ]
69
63
except NoFileError :
@@ -77,9 +71,45 @@ def __init__(
77
71
messages_to_enable .add ("fatal" )
78
72
messages_to_enable .add ("syntax-error" )
79
73
args .extend (["--disable=all" , f"--enable={ ',' .join (messages_to_enable )} " ])
74
+
75
+ # Add testoptions
76
+ self ._linter ._arg_parser .add_argument (
77
+ "--min_pyver" , type = parse_python_version , default = (2 , 5 )
78
+ )
79
+ self ._linter ._arg_parser .add_argument (
80
+ "--max_pyver" , type = parse_python_version , default = (4 , 0 )
81
+ )
82
+ self ._linter ._arg_parser .add_argument (
83
+ "--min_pyver_end_position" , type = parse_python_version , default = (3 , 8 )
84
+ )
85
+ self ._linter ._arg_parser .add_argument (
86
+ "--requires" , type = lambda s : [i .strip () for i in s .split ("," )], default = []
87
+ )
88
+ self ._linter ._arg_parser .add_argument (
89
+ "--except_implementations" ,
90
+ type = lambda s : [i .strip () for i in s .split ("," )],
91
+ default = [],
92
+ )
93
+ self ._linter ._arg_parser .add_argument (
94
+ "--exclude_platforms" ,
95
+ type = lambda s : [i .strip () for i in s .split ("," )],
96
+ default = [],
97
+ )
98
+ self ._linter ._arg_parser .add_argument (
99
+ "--exclude_from_minimal_messages_config" , default = False
100
+ )
101
+
80
102
_config_initialization (
81
103
self ._linter , args_list = args , config_file = rc_file , reporter = _test_reporter
82
104
)
105
+
106
+ self ._check_end_position = (
107
+ sys .version_info >= self ._linter .config .min_pyver_end_position
108
+ )
109
+ # TODO: PY3.9: PyPy supports end_lineno from 3.9 and above
110
+ if self ._check_end_position and IS_PYPY :
111
+ self ._check_end_position = sys .version_info >= (3 , 9 ) # pragma: no cover
112
+
83
113
self ._config = config
84
114
85
115
def setUp (self ) -> None :
@@ -88,26 +118,26 @@ def setUp(self) -> None:
88
118
f"Test cannot run with Python { sys .version .split (' ' , maxsplit = 1 )[0 ]} ."
89
119
)
90
120
missing = []
91
- for requirement in self ._test_file . options [ " requires" ] :
121
+ for requirement in self ._linter . config . requires :
92
122
try :
93
123
__import__ (requirement )
94
124
except ImportError :
95
125
missing .append (requirement )
96
126
if missing :
97
127
pytest .skip (f"Requires { ',' .join (missing )} to be present." )
98
- except_implementations = self ._test_file . options [ " except_implementations" ]
128
+ except_implementations = self ._linter . config . except_implementations
99
129
if except_implementations :
100
130
if platform .python_implementation () in except_implementations :
101
131
msg = "Test cannot run with Python implementation %r"
102
132
pytest .skip (msg % platform .python_implementation ())
103
- excluded_platforms = self ._test_file . options [ " exclude_platforms" ]
133
+ excluded_platforms = self ._linter . config . exclude_platforms
104
134
if excluded_platforms :
105
135
if sys .platform .lower () in excluded_platforms :
106
136
pytest .skip (f"Test cannot run on platform { sys .platform !r} " )
107
137
if (
108
138
self ._config
109
139
and self ._config .getoption ("minimal_messages_config" )
110
- and self ._test_file . options [ " exclude_from_minimal_messages_config" ]
140
+ and self ._linter . config . exclude_from_minimal_messages_config
111
141
):
112
142
pytest .skip ("Test excluded from --minimal-messages-config" )
113
143
@@ -116,8 +146,8 @@ def runTest(self) -> None:
116
146
117
147
def _should_be_skipped_due_to_version (self ) -> bool :
118
148
return (
119
- sys .version_info < self ._test_file . options [ " min_pyver" ]
120
- or sys .version_info > self ._test_file . options [ " max_pyver" ]
149
+ sys .version_info < self ._linter . config . min_pyver
150
+ or sys .version_info > self ._linter . config . max_pyver
121
151
)
122
152
123
153
def __str__ (self ) -> str :
0 commit comments