2

I want to run one specific unit test from my app bank/tests.py in the pipeline but I keep getting errors, I believe I am missing something on the syntax here

This is my test:

class SettingsTestCase(TestCase):
    def test_timezone_default(self):
        target_timezone = 'Europe/Copenhagen'
        self.assertEqual(target_timezone, settings.TIME_ZONE)
    print("Test: Correct timezone")

This is how I call the test in the pipeline:

...
script:
    - echo "Unit test...."
    - python manage.py test bank/tests.py:SettingsTestCase.test_timezone_default
...

This is the error message when the pipeline fails:

RROR: bank/tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: bank/tests
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/unittest/loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
ModuleNotFoundError: No module named 'bank/tests'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

Any suggestions?

patbet
  • 93
  • 1
  • 9
  • 1
    Hello fellow Copenhagener. :) So have you tried reading documentation ? https://docs.djangoproject.com/en/4.0/topics/testing/overview/ According to it, if you wanna provide the path to where the test file is, you need to write a / at the end of it. So I would suggest trying python manage.py test bank/ – Ball Hog Jan 12 '22 at 22:44

1 Answers1

2

Try this:

python manage.py test bank.tests.SettingsTestCase.test_timezone_default
Alain Bianchini
  • 3,883
  • 1
  • 7
  • 27