测试未在GitHub操作中找到

huangapple go评论50阅读模式
英文:

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
测试未在GitHub操作中找到

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
测试未在GitHub操作中找到

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.

huangapple
  • 本文由 发表于 2023年2月19日 20:57:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75500304.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定