Skip to content

Commit e2ff762

Browse files
committed
Clarify language in test comments
1 parent 3f3b5ba commit e2ff762

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

pytest_arraydiff/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,16 @@ def pytest_runtest_call(self, item):
312312
if filename is None:
313313
if single_reference:
314314
filename = item.originalname + '.' + extension
315-
else:
315+
elif derive_classes:
316316
filename = test_name
317317
filename = filename.replace('.', '_')
318318
filename = filename + '.' + extension
319319
filename = filename.replace('[', '_').replace(']', '_')
320320
filename = filename.replace('_.' + extension, '.' + extension)
321+
else:
322+
filename = item.name + '.' + extension
323+
filename = filename.replace('[', '_').replace(']', '_')
324+
filename = filename.replace('_.' + extension, '.' + extension)
321325

322326
# What we do now depends on whether we are generating the reference
323327
# files or simply running the test.

tests/test_pytest_arraydiff.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,54 @@ def test_single_reference(self, spam):
176176

177177
def test_nofile():
178178
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

Comments
 (0)