Github Actions 在 Django 项目中找不到 pytest 测试

问题描述 投票:0回答:1

由于某种原因,当我在 Django 项目上使用 Pytest 时,操作找不到任何测试。如果有帮助的话,我最初使用 Django 测试框架进行了测试,但仍然找不到任何测试。

这是 django.yml:


on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.12]

    steps:
    - uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip' # caching pip dependencies
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Run Tests
      run: |
        pytest -v

测试可以在主分支中找到。在我本地电脑上测试发现没有问题,测试文件名遵循命名程序。

这是 pytest.ini 文件:

[pytest] DJANGO_SETTINGS_MODULE = playlist_analyser.settings python_files = tests.py *_tests.py

文件名示例如下:

PlaylistAnalyser/playlist_analyser/tests/playlist_tests.py

这是文件中的测试示例(没有错误):

@pytest.fixture
def handler():
    yield PlaylistHandler()

#------------------ Get_Avg_Of_Attribute Tests ------------------#
@pytest.mark.django_db
def test_get_avg_attributes(handler):
    playlist_url = "https://open.spotify.com/playlist/6cUbe8r2kP140bL0Z2HHXV?si=89cbce6452b84b10"
    playlist = handler.get_playlist(playlist_url)
    avg_attributes = playlist.get_avg_attributes()
    
    assert avg_attributes['Energy'] == 77
    assert avg_attributes['Danceability'] == 46
    assert avg_attributes['Acousticness'] == 17
    assert avg_attributes['Valence'] == 39
    assert avg_attributes['Loudness'] == -5.86
    assert avg_attributes['Tempo'] == 131
    assert avg_attributes['Duration'] == 222

这就是输出的样子:

Run pytest -v
  pytest -v
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.12.1/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.12.1/x64/lib
============================= test session starts ==============================
platform linux -- Python 3.12.1, pytest-7.4.4, pluggy-1.3.0 -- /opt/hostedtoolcache/Python/3.12.1/x64/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/PlaylistAnalyser/PlaylistAnalyser
plugins: django-4.7.0
collecting ... collected 0 items

============================ no tests ran in 0.02s =============================
Error: Process completed with exit code 5.
django continuous-integration pytest github-actions
1个回答
0
投票

好吧,由于某种原因,它自行修复,没有进行任何更改。

© www.soinside.com 2019 - 2024. All rights reserved.