about summary refs log tree commit diff
path: root/setup_commands/run_tests.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-04 09:28:29 +0300
committerFrederick Muriuki Muriithi2023-08-04 10:20:09 +0300
commitf7fcbbcc014686ac597b783a8dcb38b43024b9d6 (patch)
treefcd69ffe3113c95f1dffa4a26dd5a65f9689caf9 /setup_commands/run_tests.py
downloadgn-auth-f7fcbbcc014686ac597b783a8dcb38b43024b9d6.tar.gz
Initialise the repository.
Diffstat (limited to 'setup_commands/run_tests.py')
-rw-r--r--setup_commands/run_tests.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/setup_commands/run_tests.py b/setup_commands/run_tests.py
new file mode 100644
index 0000000..1bb5dab
--- /dev/null
+++ b/setup_commands/run_tests.py
@@ -0,0 +1,40 @@
+import os
+import sys
+from distutils.core import Command
+
+class RunTests(Command):
+    """
+    A custom command to run tests.
+    """
+    description = "Run the tests"
+    test_types = (
+        "all", "unit", "integration", "performance")
+    user_options = [
+        ("type=", None,
+         f"""Specify the type of tests to run.
+         Valid types are {tuple(test_types)}.
+         Default is `all`.""")]
+
+    def __init__(self, dist):
+        """Initialise the command."""
+        super().__init__(dist)
+        self.command = "pytest"
+
+    def initialize_options(self):
+        """Initialise the default values of all the options."""
+        self.type = "all"
+
+    def finalize_options(self):
+        """Set final value of all the options once they are processed."""
+        if self.type not in RunTests.test_types:
+            raise Exception(f"""
+            Invalid test type (self.type) requested!
+            Valid types are
+            {tuple(RunTests.test_types)}""")
+
+        if self.type != "all":
+            self.command = f"pytest -m {self.type}_test"
+    def run(self):
+        """Run the chosen tests"""
+        print(f"Running {self.type} tests")
+        os.system(self.command)