1

I am testing someone elses code with the aim of achieving full coverage, then refactoring while testing. This code has functions which output large arrays with hundreds of elements. The arrays are generated such that I would like to test each value in the array (np.array_equal). Is there a clean way to do this with pytest? I am a bit wary of doing something like:

@pytests.mark.unittest
def test_array_function():
    expected_result = # explicitly copy and paste a large numpy array with hundreds of elements
    result = array_function()
    assert np.array_equal(result, expected_result)

EDIT

I have found a similar question here which looks good at first glance. I think this is too complicated for my use case however. I don't understand why the need of creating another temporary directory and moving all expected data files there...

user32882
  • 5,094
  • 5
  • 43
  • 82
  • You could store them in external files (`csv`. `npy`, ...) and then load the arrays dynamically via `pandas` or `np.load` or so on. – Mateen Ulhaq Jun 06 '20 at 04:08
  • Is the main issue here that you don't want to see a bunch of numbers in your unittest code? – Mateen Ulhaq Jun 06 '20 at 04:09
  • @MateenUlhaq Yes, that is the main issue here. Where should these files reside? Should I put them in the input or output test directory? How should I ready them into my test? Is there a `pytest` specific way of doing this? – user32882 Jun 06 '20 at 04:14

0 Answers0