pytest_demo_实战2_fixture应用
1、py文件所在文件夹下创建 __init__.py 文件 2、文件夹目录下:创建conftest.py import pytest # @pytest.fixture() 里面没有参数,那么默认scope="function", 也就是此时的级别 function,针对函数有效 """ firture相对于setup和teardown来说应该有以下几点优势 命名方式灵活,不局限于setup和teardown这几个命名 conftest.py 配置里可以实现数据共享,不需要import就能自动找到一些配置 scope="module" 可以实现多个.py跨文件共享前置 scope="session" 以实现多个.py跨文件使用一个session来完成多个用例 """ @pytest.fixture() def test(): print("pytest测试") 3、创建 test_02.py """ 小说网站 """ import pytest import requests import urllib3 from lxml import etree urllib3.disable_warnings() class Test: s = requests.session() uri = "https://so.88dush.com" def test_01(self, test):