I am trying to do an automated test.
There should be 21 tests, but github-actions can't find them for some reason.
https://github.com/duri0214/portfolio/actions/runs/4215160033/jobs/7316095166#step:3:6 https://github.com/duri0214/portfolio/actions/runs/4215160033/jobs/7316095166#step:3:6
manage.py 位于 mysite 目录下,所以...
(以下是我在本地PC上运行时的情况)
(venv) PS D:\OneDrive\dev\portfolio\mysite> python manage.py test
Found 21 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
:
self.client.post(reverse('vnm:likes', kwargs={'user_id': 1, 'article_id': 99}), follow=True)
AssertionError: ObjectDoesNotExist not raised
======================================================================
FAIL: test_post_click_good_button
(vietnam_research.tests.test_views.TestView)
----------------------------------------------------------------------
OK
有人知道解决办法吗?
谢谢
查看您的存储库后(https://github.com/duri0214/portfolio https://github.com/duri0214/portfolio)并在我这边进行本地测试,我发现__init__.py
失踪。也许,这是因为它被添加到您的.gitignore https://github.com/duri0214/portfolio/blob/master/.gitignore#L7文件阻止其包含在您的存储库中。
这是我测试的示例工作流程:
name: python_test
on: workflow_dispatch
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
repository: duri0214/portfolio
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
cache: pip
- name: Set up and run tests
run: |
python3 --version
python3 -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
cd mysite
touch ./vietnam_research/__init__.py
touch ./vietnam_research/tests/__init__.py
python manage.py test
您可以观察__init__.py
在最后一步中手动创建。
所以,你必须删除__init__.py
从你的.gitignore
文件并将其推送到您的存储库。
除此之外,你还需要cd mysite
首先在运行测试命令之前。此外,您的测试似乎正在使用数据库和环境变量才能成功运行。因此,您必须配置数据库(如果需要)并通过 GitHub Secret 相应地设置环境变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)