about summary refs log tree commit diff
path: root/setup_commands
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-02-14 06:56:32 +0300
committerFrederick Muriuki Muriithi2022-02-17 06:37:30 +0300
commit74044f3c7985308b4996da3a52f91c5c20a19194 (patch)
treed86714b859b31cbbd1755522f8abd8eed16e321b /setup_commands
parent67f517aa0f44f55dc691ffd791bf22ef7af0b02c (diff)
downloadgenenetwork3-74044f3c7985308b4996da3a52f91c5c20a19194.tar.gz
Use pytest's "mark" feature to categorise tests
Use pytest's `mark` feature to explicitly categorise the tests and run them
per category
Diffstat (limited to 'setup_commands')
-rw-r--r--setup_commands/run_tests.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/setup_commands/run_tests.py b/setup_commands/run_tests.py
index 9a2c9ad..1bb5dab 100644
--- a/setup_commands/run_tests.py
+++ b/setup_commands/run_tests.py
@@ -7,21 +7,18 @@ class RunTests(Command):
     A custom command to run tests.
     """
     description = "Run the tests"
-    commands = {
-        "all": "pytest",
-        "unit": "pytest tests/unit",
-        "integration": "pytest tests/integration",
-        "performance": "pytest tests/performance",
-    }
+    test_types = (
+        "all", "unit", "integration", "performance")
     user_options = [
         ("type=", None,
          f"""Specify the type of tests to run.
-         Valid types are {tuple(commands.keys())}.
+         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."""
@@ -29,13 +26,15 @@ class RunTests(Command):
 
     def finalize_options(self):
         """Set final value of all the options once they are processed."""
-        if self.type not in RunTests.commands.keys():
+        if self.type not in RunTests.test_types:
             raise Exception(f"""
             Invalid test type (self.type) requested!
             Valid types are
-            {tuple(RunTests.commands.keys())}""")
+            {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(RunTests.commands[self.type])
+        os.system(self.command)