07、pytest指定要运行哪些用例

官方用例

shell 复制代码
# 目录结构
|
|----test_mod.py
|
|----testing
		|
		|----test_dir.py
python 复制代码
# content of test_mod.py
import pytest

def func(x):
    return x + 1

def test_mod():
    print("test_mod function was invoked")
    assert func(3) == 5
    
def test_func():
    print("test_func was invoked")
    assert 0
    
@pytest.mark.slow
def test_slow_func():
    print("test_slow_func was invoked.")
    assert 0
    
class TestMyClass:
    def test_something(self):
        print("TestMyClass.test_something was invoked")
        assert 0
        
    def test_method_simple(self):
        print("TestMyClass.test_method_simple was invoked")
        assert 0
        
class TestClass:
    def test_method(self):
        print("test_method was invoked.")
        assert 0
python 复制代码
# content of test_dir.py

def test_dir():
    print("test_dir function was invoked")
    assert 3 == 5

解读与实操

  • 只运行test_mod.py模块里面的测试用例


  • 运行testing目录及子目录下的测试用例
  • 运行文件名、类名、方法名中包含MyClass但不包含method的所有用例,例如TestMyClass.test_someting会运行,但TestMyClass.test_method_simple不会运行,Windows下用"",Linux或Mac下可使用''或""
  • 运行test_mod.py模块下的test_func函数
  • 运行test_mod.py模块下的TestClass类下的test_method函数
  • 运行被@pytest.mark.slow装饰的测试用例

场景应用

  1. 编写好了一个新的测试用例,想单独调试一下;
  2. 代码提测后,某个模块发生了改动,要调试一下;
  3. 生产环境与测试环境回归内容不同,根据mark要进行区分

以上场景,都可以通过指定要运行哪些用例来完成。

相关推荐
欲游山河十万里7 小时前
pytest(三)——参数化@pytest.mark.parametrize
pytest
奶茶精Gaaa4 天前
pytest
pytest
霍格沃兹测试开发学社测试人社区6 天前
软件测试学习笔记丨Pytest 学习指南
软件测试·笔记·测试开发·学习·pytest
神即道 道法自然 如来8 天前
测试面试题:pytest断言时,数据是符点类型,如何断言?
pytest
high_tea8 天前
pytest - 多线程提速
python·pytest
傻啦嘿哟10 天前
自动化测试框架集成:将Selenium集成到pytest与unittest中
selenium·测试工具·pytest
一名在八月份找工作的测试员10 天前
自动化学习1:pytest自动化框架的基本用法:注意事项/断言assert/测试结果分析
学习·自动化·pytest
什么时候才能变强11 天前
Pytest-如何将allure报告发布至公司内网
linux·服务器·pytest
一名在八月份找工作的测试员12 天前
自动化学习2:pytest的高级用法(mark标记/fixture/hook)
学习·自动化·pytest