python - 使用 pytest 时 travis ci 没有收集我的测试

标签 python travis-ci

我已经在谷歌上搜索这个问题一个多小时了,完全不知道该怎么做 - 我正在尝试在我的公共(public)仓库上设置 travis ci ,由于某种原因,每次我提交和构建时,我总是得到这个:

============================= test session starts ==============================
platform linux2 -- Python 2.7.13, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: /home/travis/build/epitone/digitron, inifile:
plugins: cov-2.5.1
collected 0 items                                                               
========================= no tests ran in 0.01 seconds =========================
The command "pytest" exited with 5.
Done. Your build exited with 1.

由于某种原因,即使在我的本地计算机上,我的测试也没有被收集,pytest 运行得很好,甚至通过了我设置的(单个)测试。有谁知道到底发生了什么吗?

我的目录设置是这样的:

digitron/
├── bot.py
├── lib
│   ├── _config.py
│   ├── config.py
│   ├── __init__.py
│   └── utils.py
├── README.md
├── requirements.txt
└── tests
    └── auth_test.py

我的 .travis.yml 文件:

language: python
python:
  - "2.7"
  - "3.2"
  - "3.3"
  - "3.4"
  - "3.5"
  - "3.6"
  - "nightly" # currently points to 3.7-dev
before_install:
    - pip install pytest pytest-cov
# command to install dependencies
install: "pip install -r requirements.txt"
# command to run tests
script: pytest

我的requirements.txt 文件包含:

pytest>=3.2.1
py>=1.4.31
pluggy>=0.4.0

我的 auth_test.py 文件很简单:

"""
Testing for Digitron
"""
#  Necessary to find parent directory
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import bot
import pytest

    def test_connect():
        """Test connect() method in bot.py

        Returns True or false
        """
        assert(bot.connect("irc.chat.twitch.tv", 6667, "oauth:key", "username", "#channel")) == True

我基本上是在这里抓狂,试图找出我做错了什么 - 谷歌搜索错误代码 5 没有得到任何结果,我什至按照别人的设置进行操作,但仍然一无所获 - 是吗?我缺少什么吗?

编辑:尝试在 pytest 命令中显式调用测试/目录 - 在本地工作,在 travis.ci 上再次失败

最佳答案

  1. 虽然我无法判断这是否是问题的原因,但至少强制 sys.path 的方法不是很正统。 pytest 自动执行此操作:https://docs.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code因此可能存在导入问题。

  2. 错误号5是由于pytest没有找到任何测试引起的,参见documentation

  3. 可能的分辨率测试:

    1. 将测试文件重命名为 test_auth.py
    2. 将诊断信息添加到脚本中:pwdls 等。尝试简单地执行文件:pythontests/auth_test.py

评论的格式有点长且烦人,因此是答案。

关于python - 使用 pytest 时 travis ci 没有收集我的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46018315/

相关文章:

python - 导入错误 : cannot import name '_safe_split'

python - AWS Lambda 部署包每次更新都需要分钟代码更改

Travis-CI:在 .travis.yml 文件的 deploy 部分使用环境变量

python - 如何在 travis 构建期间更新 tox 上的设置工具

node.js - 特拉维斯 CI : unable to upgrade npm version

java - Cobertura 检查 Travis CI 失败

java - 使用 travis 在 javaproject 上设置 postgres 数据库

python - 有没有办法让这个 Python kNN 函数更高效?

python - 使用 Django 创建 "classes"

python - 如何点击通过gtk.Window?