You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions无法识别21个自动化测试用例的问题求助

本地能找到21个Django测试用例,但GitHub Actions无法识别

本地运行python manage.py test可找到21个测试用例,但GitHub Actions执行时却识别不到任何测试。项目中manage.py位于mysite目录下。

本地终端输出

(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

GitHub Actions执行异常表现

执行测试时未找到任何测试用例,测试结果显示0 tests run。


可能的解决办法

  • 修正工作流执行路径:在GitHub Actions的测试步骤中,先切换到mysite目录再执行测试命令,比如添加cd mysite后再运行python manage.py test。
  • 检查测试文件命名:Django仅自动识别test_*.py命名的测试文件,确认项目中测试文件都符合该规则,且未被.gitignore排除。
  • 确认依赖完整性:确保GitHub Actions环境中已安装所有项目依赖,比如通过pip install -r requirements.txt完整安装requirements.txt内的所有包。
  • 指定测试模块运行:尝试在GitHub Actions中直接指定测试模块执行,比如python manage.py test vietnam_research,排查是否是自动发现机制的问题。
  • 核对Django配置:检查settings.py中的INSTALLED_APPS是否包含测试所在的应用,确保应用已正确注册到项目中。

内容的提问来源于stack exchange,提问作者yoshitaka okada

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 10:20:22