python - Unittest tearDown() method depends on finished test -
i write selenium tests, , have problem. before each test upload different files every test, , after test done, want remove these files application if test failed. there 2 methods setup
, teardown
. called before , after every test, how can define test finished in teardown
method? important me, because after each test want remove different files application, depending on finished test.
i want like:
def teardown(self): if test1_is_finished(): remove_test1_files if test2_is_finished(): remove_test2_files # , on
i new python , selenium tests, , maybe better approach exists job after after test finished, if failed.
in setup
method (to run before every test), create list, to_be_removed
:
def setup(self): self.to_be_removed = []
in each unit test, append filenames to_be_removed
:
def test1(self): ... self.to_be_removed.append(filename)
then, in teardown
, remove files listed in to_be_removed
:
def teardown(self): filename in self.to_be_removed: os.unlink(filename)
this way, can handle teardown
s same way.
Comments
Post a Comment