【发布时间】:2021-01-21 22:06:23
【问题描述】:
我正在尝试调试我的第一个 django 测试,但 VSCode 正在返回:在 0.000 秒内运行 0 个测试。 另一方面,当我在 VSCode 终端或外部使用集成的 git bash(我使用的是 Windows 操作系统)时,它会返回: Ran 1 test in 0.0014s。它还回显 FAILED 和测试中有效错误的回溯。
我的 vscode launch.json:
{
...
"configurations": [
...
{
"name": "Django Tests",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\testprojectname\\manage.py",
"args": [
"test"
],
"django": true,
}
]
}
我的 vscode settings.json:
{
"python.pythonPath": "C:\\Users\\user\\.virtualenvs\\backend-Vg-KBKTA\\Scripts\\python.exe",
"python.testing.pytestEnabled": true,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestArgs": [
"testprojectname"
]
}
- 请注意,C:\Users\user\.virtualenvs\backend-Vg-KBKTA\Scripts\python.exe 是 pipenv shell 的有效路径 [(1) 当我输入 bash 时会回显它: pipenv - -venv (2) 它在我启动 django 调试器时起作用]
到目前为止,我已经尝试过:
- 根据更新我的 pytest VSCode pytest test discovery fails
- 将我的 tests.py 文件的名称更改为 test_example.py 根据 Pytest - no tests ran
- 根据 (2) 中的相同链接将测试的类更改为前缀为 Test_
这是当前测试的样子
class Test_Contacts(unittest.TestCase):
def test_create_contact_message(self):
"""Create a new contact message."""
url = reverse('message-list')
data = {
'first_name': 'DabApps',
'last_name': 'jack',
'email': 'giehogho24h@gmo8y9tgail.com',
'message': 'hi, how are you?',
'message_type': 1
}
# this is just random code to cause an error
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Message.objects.count(), 1)
self.assertEqual(Message.objects.get().name, 'DabApps')
【问题讨论】:
标签: django visual-studio testing pytest pipenv