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?

1
  • 1
    Hello fellow Copenhagener. :) So have you tried reading documentation ? 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/ Commented Jan 12, 2022 at 22:44

1 Answer 1

3

Try this:

python manage.py test bank.tests.SettingsTestCase.test_timezone_default
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.