pytest вызывает прибор на уровне модуля для каждой ожидаемой тестовой функции, если прибор должен вызываться только один раз для модуля
#content of test_fin.py
import pytest
import time
import logging
@pytest.fixture
def do_setup_tear(scope="module"):
logging.getLogger().info('doing setup stuff if needed')
yield None
logging.getLogger().info('teardown')
def test_do_this():
time.sleep(5)
assert True
def test_do_that(do_setup_tear):
time.sleep(5)
assert True
def test_do_thing(do_setup_tear):
time.sleep(5)
assert True
фактический результат:
============================= test session starts =============================
platform win32 -- Python 3.7.0, pytest-5.2.2, py-1.8.0, pluggy-0.13.0
rootdir: C:\Users\<username>\PycharmProjects\blabla\tests, inifile: pytest.ini
plugins: allure-pytest-2.8.6
collected 3 items
test_fin.py::test_do_this PASSED [ 33%]
test_fin.py::test_do_that
------------------------------- live log setup --------------------------------
2019-10-25 12:12:36 INFO doing setup stuff if needed
PASSED [ 66%]
------------------------------ live log teardown ------------------------------
2019-10-25 12:12:41 INFO teardown
test_fin.py::test_do_thing
------------------------------- live log setup --------------------------------
2019-10-25 12:12:41 INFO doing setup stuff if needed
PASSED [100%]
------------------------------ live log teardown ------------------------------
2019-10-25 12:12:46 INFO teardown
============================= 3 passed in 15.06s ==============================
Я что-то здесь упустил,если я изменю scope="module"
на `scope =" function ", я получу такой же вывод