我想从管道中的应用程序bank/tests.py 运行一个特定的单元测试,但我不断收到错误,我相信我在此处的语法中遗漏了一些内容
这是我的测试:
class SettingsTestCase(TestCase):
def test_timezone_default(self):
target_timezone = 'Europe/Copenhagen'
self.assertEqual(target_timezone, settings.TIME_ZONE)
print("Test: Correct timezone")
这就是我在管道中调用测试的方式:
...
script:
- echo "Unit test...."
- python manage.py test bank/tests.py:SettingsTestCase.test_timezone_default
...
这是管道失败时的错误消息:
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
有什么建议吗?
最佳答案
试试这个:
python manage.py test bank.tests.SettingsTestCase.test_timezone_default
关于Django unittest 运行特定测试语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70689236/