Skip to content

Commit 2794f4f

Browse files
committed
Enforce setting __test_path__ BAZEL_BIN_DIR and BAZEL_TESTLOGS_DIR
1 parent 936bd93 commit 2794f4f

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

test/unit/common/base.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,31 @@ class TestBase(unittest.TestCase):
2929
"""Unittest base abstract class"""
3030

3131
# This variable must be overwritten in each subclass!
32-
__test_path__: str = os.path.abspath(__file__)
32+
__test_path__: str = None
33+
BAZEL_BIN_DIR: str = None
34+
BAZEL_TESTLOGS_DIR: str = None
3335

3436
@classmethod
3537
def setUpClass(cls):
3638
"""Load module, save environment"""
39+
ErrorCollector: list[str] = []
40+
if cls.__test_path__ == None:
41+
ErrorCollector.append(
42+
"Test path must be overwritten! Use:"
43+
"\n__test_path__ = os.path.dirname(os.path.abspath(__file__))"
44+
)
45+
if cls.BAZEL_BIN_DIR == None:
46+
ErrorCollector.append(
47+
"Bazel bin directory must be overwritten! Use:"
48+
"../../../bazel-bin/test/unit/my_test_folder"
49+
)
50+
if cls.BAZEL_TESTLOGS_DIR == None:
51+
ErrorCollector.append(
52+
"Bazel test logs directory must be overwritten! Use:"
53+
"../../../bazel-testlogs/test/unit/my_test_folder"
54+
)
55+
if ErrorCollector:
56+
raise NotImplementedError("\n".join(ErrorCollector))
3757
# Enable debug logs for tests if "super verbose" flag is provided
3858
if "-vvv" in sys.argv:
3959
logging.basicConfig(

test/unit/test_template.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
import unittest
2020
from common.base import TestBase
2121

22-
# TODO: fix folder name
23-
BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test",
24-
"unit", "my_test_folder")
25-
BAZEL_TESTLOGS_DIR = os.path.join("../../..", "bazel-testlogs", "test",
26-
"unit", "my_test_folder")
2722

2823
class TestTemplate(TestBase):
2924
"""TODO: Add a description"""
3025
# Set working directory
3126
__test_path__ = os.path.dirname(os.path.abspath(__file__))
27+
# TODO: fix folder name
28+
BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test",
29+
"unit", "my_test_folder")
30+
BAZEL_TESTLOGS_DIR = os.path.join("../../..", "bazel-testlogs", "test",
31+
"unit", "my_test_folder")
3232

3333
def setUp(self):
3434
"""TODO: Define clean up before every test"""

0 commit comments

Comments
 (0)