unittests: use UnitTest.addCleanup a bit

pull/9628/head
Dylan Baker 4 years ago committed by Nirbheek Chauhan
parent 905a361ca0
commit 457e2d9812
  1. 25
      unittests/allplatformstests.py

@ -1499,19 +1499,22 @@ class AllPlatformTests(BasePlatformTests):
else: else:
shlibfile = os.path.join(tdir, 'libalexandria.' + shared_suffix) shlibfile = os.path.join(tdir, 'libalexandria.' + shared_suffix)
self.build_shared_lib(cc, source, objectfile, shlibfile, impfile) self.build_shared_lib(cc, source, objectfile, shlibfile, impfile)
# Run the test
try: if is_windows():
self.init(tdir) def cleanup() -> None:
self.build() """Clean up all the garbage MSVC writes in the source tree."""
self.run_tests()
finally:
os.unlink(shlibfile)
if is_windows():
# Clean up all the garbage MSVC writes in the
# source tree.
for fname in glob(os.path.join(tdir, 'alexandria.*')): for fname in glob(os.path.join(tdir, 'alexandria.*')):
if os.path.splitext(fname)[1] not in ['.c', '.h']: if os.path.splitext(fname)[1] not in {'.c', '.h'}:
os.unlink(fname) os.unlink(fname)
self.addCleanup(cleanup)
else:
self.addCleanup(os.unlink, shlibfile)
# Run the test
self.init(tdir)
self.build()
self.run_tests()
@skipIfNoPkgconfig @skipIfNoPkgconfig
def test_pkgconfig_static(self): def test_pkgconfig_static(self):

Loading…
Cancel
Save