summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoris Roovers <joris.roovers@gmail.com>2021-09-27 16:24:00 +0200
committerJoris Roovers <joris.roovers@gmail.com>2021-09-27 16:24:00 +0200
commitff601f67b7b2812cb867dd1412f18f421fe93894 (patch)
treef7af9818b5d3c08673b03f2c51ab4413258fb33b
parentc5fcff0692eb84b7b43cace42e4b0eea799f52c6 (diff)
New git repo per integration test
Every integration test function now runs inside its own git repo. Before we created a new git repo per test class (not function). This sometimes caused side effects where integration tests would fail or pass depending on the order they were run in.
-rw-r--r--qa/base.py29
-rw-r--r--qa/test_hooks.py2
2 files changed, 13 insertions, 18 deletions
diff --git a/qa/base.py b/qa/base.py
index 0d844d4..d3c8e81 100644
--- a/qa/base.py
+++ b/qa/base.py
@@ -31,24 +31,18 @@ class BaseTestCase(TestCase):
GIT_CONTEXT_ERROR_CODE = 254
GITLINT_USAGE_ERROR = 253
- @classmethod
- def setUpClass(cls):
- """ Sets up the integration tests by creating a new temporary git repository """
- cls.tmp_git_repos = []
- cls.tmp_git_repo = cls.create_tmp_git_repo()
-
- @classmethod
- def tearDownClass(cls):
- """ Cleans up the temporary git repositories """
- for repo in cls.tmp_git_repos:
- shutil.rmtree(repo)
-
def setUp(self):
+ """ Sets up the integration tests by creating a new temporary git repository """
self.tmpfiles = []
+ self.tmp_git_repos = []
+ self.tmp_git_repo = self.create_tmp_git_repo()
def tearDown(self):
+ # Clean up temporary files and repos
for tmpfile in self.tmpfiles:
os.remove(tmpfile)
+ for repo in self.tmp_git_repos:
+ shutil.rmtree(repo)
def assertEqualStdout(self, output, expected): # pylint: disable=invalid-name
self.assertIsInstance(output, RunningCommand)
@@ -56,16 +50,15 @@ class BaseTestCase(TestCase):
output = output.replace('\r', '')
self.assertMultiLineEqual(output, expected)
- @classmethod
- def generate_temp_path(cls):
+ @staticmethod
+ def generate_temp_path():
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
return os.path.realpath(f"/tmp/gitlint-test-{timestamp}")
- @classmethod
- def create_tmp_git_repo(cls):
+ def create_tmp_git_repo(self):
""" Creates a temporary git repository and returns its directory path """
- tmp_git_repo = cls.generate_temp_path()
- cls.tmp_git_repos.append(tmp_git_repo)
+ tmp_git_repo = self.generate_temp_path()
+ self.tmp_git_repos.append(tmp_git_repo)
git("init", tmp_git_repo)
# configuring name and email is required in every git repot
diff --git a/qa/test_hooks.py b/qa/test_hooks.py
index ea58699..b78100e 100644
--- a/qa/test_hooks.py
+++ b/qa/test_hooks.py
@@ -17,6 +17,7 @@ class HookTests(BaseTestCase):
'gitlint: \x1b[31mYour commit message contains violations.\x1b[0m\n']
def setUp(self):
+ super().setUp()
self.responses = []
self.response_index = 0
self.githook_output = []
@@ -40,6 +41,7 @@ class HookTests(BaseTestCase):
f"{self.tmp_git_repo}/.git/hooks/commit-msg\n")
self.assertEqualStdout(output_uninstalled, expected_uninstalled)
+ super().tearDown()
def _violations(self):
# Make a copy of the violations array so that we don't inadvertently edit it in the test (like I did :D)