June 2019
Beginner to intermediate
770 pages
19h 24m
English
In many cases, a test case may require a particular OS environment. When working with external resources such as files, directories, or processes, we may need to create or initialize them before a test. We may also need to remove the resources before a test, or we may need to tear down the resources at the end of the test.
Let's assume that we have a function, rounds_final(), which is supposed to process a given file. We need to test the function's behavior in the rare case that the file doesn't exist. It's common to see TestCase with a structure such as the following one:
import osclass Test_Missing(unittest.TestCase): def setUp(self) -> None: try: (Path.cwd() / "data" / "ch17_sample.csv").unlink() ...
Read now
Unlock full access