1- from dataclasses import asdict
21from unittest import TestCase
32
43from rplugin .python3 .ultest .handler .parsers .output import OutputParser
54from rplugin .python3 .ultest .handler .parsers .output .python .pytest import (
65 ParseResult ,
76 failed_test_section ,
8- failed_test_section_code ,
97 failed_test_section_error_message ,
108 failed_test_section_title ,
119)
@@ -86,6 +84,27 @@ def test_parse_file(self):
8684 ],
8785 )
8886
87+ def test_parse_hypothesis_file (self ):
88+ output = get_output ("pytest_hypothesis" )
89+ parser = OutputParser ([])
90+ result = parser .parse_failed ("python#pytest" , output )
91+ self .assertEqual (
92+ result ,
93+ [
94+ ParseResult (
95+ name = "test_get_nearest_from_strict_match" ,
96+ namespaces = [],
97+ file = "tests/unit/models/test_tree.py" ,
98+ message = [
99+ "AssertionError: assert Test(id='', name='', file='', line=18, col=0, running=0, namespaces=[], type='test') != Test(id='', name='', file='', line=18, col=0, running=0, namespaces=[], type='test')" ,
100+ "+ where Test(id='', name='', file='', line=18, col=0, running=0, namespaces=[], type='test') = Tree(data=Test(id='', name='', file='', line=18, col=0, running=0, namespaces=[], type='test'), children=[]).data" ,
101+ ],
102+ output = None ,
103+ line = 34 ,
104+ )
105+ ],
106+ )
107+
89108 def test_parse_failed_test_section_title (self ):
90109 raw = "_____ MyClass.test_a ______"
91110 result = failed_test_section_title .parse (raw )
@@ -111,36 +130,6 @@ def test_parse_failed_test_section_error(self):
111130 ]
112131 self .assertEqual (expected , result )
113132
114- def test_parse_failed_test_section_code (self ):
115- self .maxDiff = None
116- raw = """self = <test_a.TestClass testMethod=test_b>
117-
118- def test_b(self):
119- > self.assertEqual({
120- "a": 1,
121- "b": 2,
122- "c": 3},
123- {"a": 1,
124- "b": 5,
125- "c": 3,
126- "d": 4})
127- E This should not be parsed"""
128- result , _ = failed_test_section_code .parse_partial (raw )
129- expected = [
130- "self = <test_a.TestClass testMethod=test_b>" ,
131- "" ,
132- " def test_b(self):" ,
133- "> self.assertEqual({" ,
134- ' "a": 1,' ,
135- ' "b": 2,' ,
136- ' "c": 3},' ,
137- ' {"a": 1,' ,
138- ' "b": 5,' ,
139- ' "c": 3,' ,
140- ' "d": 4})' ,
141- ]
142- self .assertEqual (expected , result )
143-
144133 def test_parse_failed_test_section (self ):
145134 raw = """_____________________________________________________________________ MyClass.test_b _____________________________________________________________________
146135
@@ -197,14 +186,61 @@ def a_function():
197186"""
198187 result = failed_test_section .parse (raw )
199188 self .assertEqual (
200- asdict (result ),
201- asdict (
202- ParseResult (
203- file = "test_a.py" ,
204- name = "test_c" ,
205- namespaces = ["TestClass" ],
206- message = ["Exception: OH NO" ],
207- line = 39 ,
208- )
189+ result ,
190+ ParseResult (
191+ file = "test_a.py" ,
192+ name = "test_c" ,
193+ namespaces = ["TestClass" ],
194+ message = ["Exception: OH NO" ],
195+ line = 39 ,
196+ ),
197+ )
198+
199+ def test_parse_failed_test_with_code_below_trace_location (self ):
200+ raw = """__________________________________________ test_get_nearest_from_strict_match __________________________________________
201+
202+ @given(sorted_tests())
203+ > def test_get_nearest_from_strict_match(tests: List[Union[Test, Namespace]]):
204+
205+ tests/unit/models/test_tree.py:30:
206+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
207+ tests/unit/models/test_tree.py:35: in test_get_nearest_from_strict_match
208+ logging.warn("AAAAAAH")
209+ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
210+
211+ msg = 'AAAAAAH', args = (), kwargs = {}
212+
213+ def warn(msg, *args, **kwargs):
214+ > warnings.warn("The 'warn' function is deprecated, "
215+ "use 'warning' instead", DeprecationWarning, 2)
216+ E DeprecationWarning: The 'warn' function is deprecated, use 'warning' instead
217+
218+ ../../../.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py:2058: DeprecationWarning
219+ ------------------------------------------------------ Hypothesis ------------------------------------------------------
220+ Falsifying example: test_get_nearest_from_strict_match(
221+ tests=[Test(id='', name='', file='', line=2, col=0, running=0, namespaces=[], type='test'),
222+ Test(id='', name='0', file='', line=4, col=0, running=0, namespaces=[], type='test'),
223+ Test(id='', name='', file='', line=6, col=0, running=0, namespaces=[], type='test'),
224+ Test(id='', name='', file='', line=8, col=0, running=0, namespaces=[], type='test'),
225+ Test(id='', name='', file='', line=10, col=0, running=0, namespaces=[], type='test'),
226+ Test(id='', name='', file='', line=12, col=0, running=0, namespaces=[], type='test'),
227+ Test(id='', name='', file='', line=14, col=0, running=0, namespaces=[], type='test'),
228+ Test(id='', name='', file='', line=16, col=0, running=0, namespaces=[], type='test'),
229+ Test(id='', name='', file='', line=18, col=0, running=0, namespaces=[], type='test'),
230+ Test(id='', name='', file='', line=514, col=0, running=0, namespaces=[], type='test')],
231+ )"""
232+
233+ result = failed_test_section .parse (raw )
234+ self .assertEqual (
235+ result ,
236+ ParseResult (
237+ name = "test_get_nearest_from_strict_match" ,
238+ namespaces = [],
239+ file = "tests/unit/models/test_tree.py" ,
240+ message = [
241+ "DeprecationWarning: The 'warn' function is deprecated, use 'warning' instead"
242+ ],
243+ output = None ,
244+ line = 35 ,
209245 ),
210246 )
0 commit comments