英文:
Test not found in github actions
问题
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
manage.py is under mysite directory, so...
(Below is when I run it on my local 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
Anyone know a solution?
thanks
英文:
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
manage.py is under mysite directory, so...
(Below is when I run it on my local 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
Anyone know a solution?
thanks
答案1
得分: 0
在查看了您的仓库(https://github.com/duri0214/portfolio)并在本地进行测试后,我发现 __init__.py
文件缺失。也许是因为它被添加到您的.gitignore
文件中,这阻止了它包含在您的仓库中。
以下是我测试时使用的示例工作流程:
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
在最后一步中是手动创建的。
因此,您需要从.gitignore
文件中删除 __init__.py
并将其推送到您的仓库。
除此之外,在运行测试命令之前,您需要首先cd mysite
。此外,您的测试似乎需要使用数据库和环境变量才能成功运行。因此,您需要根据需要配置数据库,并通过GitHub secrets设置环境变量。
英文:
After looking at your repo (https://github.com/duri0214/portfolio) and testing it locally on my side, I found out that __init__.py
was missing. Maybe, it was due to the fact that it was added in your .gitignore
file which prevented its inclusion in your repo.
Here's the sample workflow that I tested it with:
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
You may observe the __init__.py
being manually created in the last step.
So, you have to remove __init__.py
from your .gitignore
file and push those to your repo.
Apart from that, you need to cd mysite
first before running the test command. Also, your tests seem to be using database and environment variables to be run successfully. So, you'll have to configure the database (if required) and set the env vars via GitHub secrets accordingly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论