Commit ab609a77 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

testing.py: bugfix: teardown()-method was not called

parent d07f3b0f
......@@ -783,30 +783,26 @@ def run_tests_in_class(cls_name, namespace, methods=()):
exec("instance = " + cls + "()", nspace)
instance = nspace["instance"]
setup = instance.setup if "setup" in dir(instance) else lambda : 0
teardown = instance.teardown if "teardown" in dir(obj) else lambda : 0
teardown = instance.teardown if "teardown" in dir(instance) else lambda : 0
return instance, setup, teardown
obj = None
try:
if methods:
obj, setup, teardown = instantiate(cls_name, namespace)
for name in methods:
if methods:
obj, setup, teardown = instantiate(cls_name, namespace)
for name in methods:
func = obj.__getattribute__(name)
if callable(func):
print("Running " + cls_name + "." + name)
setup(); func(); teardown()
# exec('obj.' + name + '()')
else:
obj, setup, teardown = instantiate(cls_name, namespace)
for name in dir(obj):
if name.lower().startswith("test"):
func = obj.__getattribute__(name)
if callable(func):
print("Running " + cls_name + "." + name)
setup(); func(); teardown()
# exec('obj.' + name + '()')
else:
obj, setup, teardown = instantiate(cls_name, namespace)
for name in dir(obj):
if name.lower().startswith("test"):
func = obj.__getattribute__(name)
if callable(func):
print("Running " + cls_name + "." + name)
setup(); func(); teardown()
finally:
if "teardown" in dir(obj):
obj.teardown()
def run_test_function(func_name, namespace):
......
......@@ -268,7 +268,6 @@ class TestIncludes:
os.rmdir(self.dirname)
os.chdir(TestIncludes.cwd)
def create_files(self, files: Dict[str, str]):
for name, content in files.items():
with open(name, 'w', encoding='utf-8') as f:
......
......@@ -118,10 +118,10 @@ class TestTestfiles:
f.write(CFG_FILE_4)
def teardown(self):
os.remove(self.cfg1)
os.remove(self.cfg2)
os.remove(self.cfg3)
os.remove(self.cfg4)
if os.path.exists(self.cfg1): os.remove(self.cfg1)
if os.path.exists(self.cfg2): os.remove(self.cfg2)
if os.path.exists(self.cfg3): os.remove(self.cfg3)
if os.path.exists(self.cfg4): os.remove(self.cfg4)
os.chdir(self.save_dir)
def test_unit_from_config_file(self):
......
......@@ -50,13 +50,13 @@ class TestLoggingAndLoading:
self.LOGDIR = os.path.abspath(os.path.join(scriptpath, "TESTLOGS" + str(os.getpid())))
def teardown(self):
os.remove(self.filename)
if os.path.exists(self.filename): os.remove(self.filename)
pycachedir = os.path.join(self.dirname,'__pycache__')
if os.path.exists(pycachedir):
for fname in os.listdir(pycachedir):
os.remove(os.path.join(pycachedir, fname))
os.rmdir(pycachedir)
os.rmdir(self.dirname)
if os.path.exists(self.dirname): os.rmdir(self.dirname)
if os.path.exists(self.LOGDIR):
# for fname in os.listdir(self.LOGDIR):
# os.remove(os.path.join(self.LOGDIR, fname))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment