@@ -176,3 +176,54 @@ def test_single_reference(self, spam):
176
176
177
177
def test_nofile ():
178
178
pass
179
+
180
+ class BaseTestClass :
181
+ arrays = None
182
+ @pytest .mark .array_compare (reference_dir = reference_dir , file_format = 'text' , derive_classes = True )
183
+ def test_array_one (self ):
184
+ return self .array
185
+ class TestDerivedOne (BaseTestClass ):
186
+ array = np .arange (3 * 4 ).reshape ((3 , 4 ))
187
+
188
+ class TestDerivedTwo (BaseTestClass ):
189
+ array = np .arange (2 * 5 ).reshape ((2 , 5 ))
190
+
191
+
192
+
193
+ DERIVED_FAILING = """
194
+ import pytest
195
+ import numpy as np
196
+ class BaseTestClass:
197
+ arrays = None
198
+ @pytest.mark.array_compare(reference_dir="{reference_dir}", file_format='text')
199
+ def test_array_one(self):
200
+ return self.array
201
+ class TestDerivedOne(BaseTestClass):
202
+ array = np.arange(3 * 4).reshape((3, 4))
203
+
204
+ class TestDerivedTwo(BaseTestClass):
205
+ array = np.arange(2 * 5).reshape((2, 5))
206
+ """
207
+
208
+
209
+ def test_derived_fails ():
210
+
211
+ tmpdir = tempfile .mkdtemp ()
212
+
213
+ test_file = os .path .join (tmpdir , 'test.py' )
214
+ gen_dir = os .path .join (tmpdir , 'spam' , 'egg' )
215
+ with open (test_file , 'w' ) as f :
216
+ f .write (DERIVED_FAILING .format (reference_dir = gen_dir ))
217
+
218
+ # If we use --arraydiff, it should detect that the file is missing
219
+ code = subprocess .call (f'pytest --arraydiff { test_file } ' , shell = True )
220
+ assert code != 0
221
+
222
+ # when we generate the test files without the derive option the generation should succeed
223
+ code = subprocess .call (['pytest' , f'--arraydiff-generate-path={ gen_dir } ' , test_file ],
224
+ timeout = 10 )
225
+ assert code == 0
226
+
227
+ # but when the test is run again, it should fail, because the different tests are looking at the same file
228
+ code = subprocess .call (f'pytest --arraydiff { test_file } ' , shell = True )
229
+ assert code != 0
0 commit comments