Skip to content
Snippets Groups Projects
Commit d5eed758 authored by Simon McVittie's avatar Simon McVittie
Browse files

testutils: Move most test setup to be once per class


The result of this setup will be the same every time, so there isn't
much point in repeating it. When we add tests with time-consuming setup
like running steam-runtime-system-info, we'll only want to do that once.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 0db2c839
No related branches found
No related tags found
No related merge requests found
......@@ -80,33 +80,56 @@ class BaseTest(unittest.TestCase):
Base class with some useful test setup.
"""
def setUp(self) -> None:
self.G_TEST_SRCDIR = os.getenv(
G_TEST_BUILDDIR = ''
G_TEST_SRCDIR = ''
artifacts = ''
tmpdir = None # type: tempfile.TemporaryDirectory
top_builddir = ''
top_srcdir = ''
@classmethod
def setUpClass(cls) -> None:
cls.G_TEST_SRCDIR = os.getenv(
'G_TEST_SRCDIR',
os.path.abspath(os.path.dirname(__file__)),
)
self.top_srcdir = os.path.dirname(self.G_TEST_SRCDIR)
self.G_TEST_BUILDDIR = os.getenv(
cls.top_srcdir = os.path.dirname(cls.G_TEST_SRCDIR)
cls.G_TEST_BUILDDIR = os.getenv(
'G_TEST_BUILDDIR',
os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '_build'),
),
)
self.top_builddir = os.path.dirname(self.G_TEST_BUILDDIR)
cls.top_builddir = os.path.dirname(cls.G_TEST_BUILDDIR)
self.tmpdir = tempfile.TemporaryDirectory()
self.addCleanup(self.tmpdir.cleanup)
cls.tmpdir = tempfile.TemporaryDirectory()
artifacts = os.getenv('AUTOPKGTEST_ARTIFACTS')
if artifacts is not None:
self.artifacts = os.path.abspath(artifacts)
cls.artifacts = os.path.abspath(artifacts)
else:
self.artifacts = self.tmpdir.name
cls.artifacts = cls.tmpdir.name
def setUp(self) -> None:
cls = self.__class__
self.G_TEST_BUILDDIR = cls.G_TEST_BUILDDIR
self.G_TEST_SRCDIR = cls.G_TEST_SRCDIR
self.artifacts = cls.artifacts
self.top_builddir = cls.top_builddir
self.top_srcdir = cls.top_srcdir
# Class and each test get separate temp directories
self.tmpdir = tempfile.TemporaryDirectory()
self.addCleanup(self.tmpdir.cleanup)
def tearDown(self) -> None:
pass
@classmethod
def tearDownClass(cls) -> None:
cls.tmpdir.cleanup()
def test_main():
logging.basicConfig(level=logging.DEBUG)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment