Exercise

Write a fixture for an empty data file

When a function takes a data file as an argument, you need to write a fixture that takes care of creating and deleting that data file. This exercise will test your ability to write such a fixture.

get_data_as_numpy_array() should return an empty numpy array if it gets an empty data file as an argument. To test this behavior, you need to write a fixture empty_file() that does the following.

  • Creates an empty data file empty.txt relative to the current working directory in setup.
  • Yields the path to the empty data file.
  • Deletes the empty data file in teardown.

The fixture will be used by the test test_on_empty_file(), which is available for you to see in the script.

os, pytest, numpy as np and get_data_as_numpy_array have been imported for you.

Instructions 1/2

undefined XP
    1
    2
  • In the setup, assign the variable file_path to the correct string.
  • After the setup, yield the variable file_path so that the test can use it.
  • In the teardown, remove the file.