0

I have two functions

def complex_func():
   # generate result.csv
  
def post_process_func(csv_fname):
    # do something with result.csv

and I want to make a unittest for each function

def test_complex_func():
   complex_func()
   assert result.csv exists
   assert contents of result.csv is correct

However, to test post_process_func I need a result.csv so I need to call complex_func() and it causes dependency issue between two unittests.

I searched and found mock or patch but those are useful to override the return value of function or object, not the file IO.

What's the best way to separate these two unittests in python way?

eebeer
  • 11
  • 3
  • Depending on the contents of the file, you could use `BytesIO` to mock the contents of a file. I think reading [this](https://stackoverflow.com/a/24325868/8868327) answer might help you – EDG956 Jun 03 '22 at 19:43
  • Also if you have a working file that you could use as a fixture, just store it in your project with your tests and use it, not to depend on the function producing the file – EDG956 Jun 03 '22 at 19:47

0 Answers0