pytest由于存在test_前缀而找到了test_ehlo.测试函数需要一个名为smtp的函数参数.配套夹具 通过查找带有夹具标记的函数来发现该函数 smtp. 调用 smtp()创建实例. test_ehlo()被调用,并在测试函数的最后一行失败. pytest finds the test_ehlo because of the test_ prefix. The test function needs a function argument named smtp. A matching fixture function is discovered by looking for a fixture-marked function named smtp. smtp() is called to create an instance. test_ehlo() is called and fails in the last line of the test function.推荐答案 py.test将导入conftest.py和所有与python_files模式匹配的Python文件,默认情况下为test_*.py.如果您有测试装置,则需要从conftest.py或依赖它的测试文件中包括或导入它:py.test will import conftest.py and all Python files that match the python_files pattern, by default test_*.py. If you have a test fixture, you need to include or import it from conftest.py or from the test files that depend on it:from sonoftest import pytest_addoption, cmdopt 这篇关于py.test如何以及在哪里找到固定装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 22:48