[英]pytest: Adding fixture in the test file instead of conftest.py
I am new to Python and I have a doubt in pytest 我是Python的新手,我对pytest有疑问
test_client.py test_client.py
# Simple Example tests
import pytest
def test_one():
assert False == False
def test_two():
assert True == True
def cleanup():
# do some cleanup stuff
conftest.py conftest.py
import pytest
import test_client
@pytest.fixture(scope="session", autouse=True)
def do_clean_up(request):
request.addfinalizer(test_client.cleanup)
Is it possible to move the fixture defined in conftest.py to the test_client.py thereby eliminating having conftest.py 是否可以将conftest.py中定义的灯具移动到test_client.py从而消除conftest.py
Yes. 是。 Why didn't you simply try?
您为什么不简单尝试? ;)
;)
Fixtures are put in conftest.py
files to be able to use them in multiple test files. 灯具放在
conftest.py
文件中,以便可以在多个测试文件中使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.