使用@pytest.mark.only运行单个测试

pytest-onl的Python项目详细描述


只运行标记为@pytest.mark.only的测试。如果没有标记,则所有测试都照常运行。

mocha借来的。

安装

pip install pytest-only

用法

在功能上使用它

importpytestdeftest_that_will_not_run():assert0@pytest.mark.onlydeftest_that_will_run():assert1
$ py.test -v test_example.py

=============================test session starts==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
cachedir: .cache
rootdir: /tmp/example, inifile:
plugins: only-1.0.0
collected 2 items

test_example.py::test_that_will_run PASSED===========================1 passed in 0.00 seconds===========================

或者在课堂上使用它

importpytestclassTestThatWillNotRun:deftest_that_will_not_run(self):assert0@pytest.mark.onlyclassTestThatWillRun:deftest_that_will_run(self):assert1
$ py.test -v test_example.py

=============================test session starts==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
cachedir: .cache
rootdir: /tmp/example, inifile:
plugins: only-1.0.0
collected 2 items

test_example.py::TestThatWillRun::test_that_will_run PASSED===========================1 passed in 0.00 seconds===========================

或者在模块上使用它

# test_example.pyimportpytestpytestmark=pytest.mark.onlydeftest_that_will_run():assert1
# test_example2.pydeftest_that_will_not_run():assert0
$ py.test -v test_example.py test_example2.py

=============================test session starts==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28/bin/python3.6
cachedir: .cache
rootdir: /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28, inifile:
plugins: only-1.0.0
collected 2 items

test_example.py::test_that_will_run PASSED===========================1 passed in 0.00 seconds===========================

禁用单个测试运行

要运行所有测试,无论是否使用@pytest.mark.only,请通过 pytest的--no-only标志:

$ py.test --no-only

如果已经传递了--no-only(可能是通过addopts传入 pytest.ini,使用--only标志重新启用它:

$ py.test --no-only --only

开发

  1. 安装测试/开发要求

    $ pip install -r dev-requirements.txt
    
  2. 运行测试

    $ py.test
    
  3. 在所有当前支持的平台上运行测试

    $ tox
    

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
有没有一种方法可以将不同的java web应用程序组合到一个web应用程序(war)中而不相互影响?   java一次屏蔽两位   java如何在多个类上初始化元素?   java在后台服务中处理通知或使用GCM(或其他推送通知服务)   java从const方法调用JNI函数   javascript如何使用函数/方法返回?   Java优化:声明类变量与使用临时变量   java字符算术基数8 vs基数10   Java流收集要存储的对象列表   swing我正在用Java中的keyListener制作一个精灵移动器   在Gradle构建脚本中使用Scala(或java)方法   java Android Mediaplayer下一步按钮不起作用   Java Sound API在播放音频文件后将其锁定   java将变量从外部类传递到内部类的最佳方法   使用play framework的博客web应用程序出现java逻辑错误   java我们可以在Spring批处理中处理大型zip文件吗?   java如何检查JTable的选定行的特定列中的值是否已经在JList中?