问题描述
我正在尝试使用 setup()
对我的方法 pytest
进行单元测试。但是在当前的测试中,nose.py
会抛出一个 TypeError: setup() missing 1 required positional argument
。
setup_config.py(来自 setupmodule)
def setup(config):
config.name = "prod"
run.py(来自 runmodule)
from typing import Callable
def run(setup_fn: Callable):
config = get_config()
setup_fn(config)
return config
实际测试:test_run.py
from setupmodule.setup_config import setup
from runmodule.run import run
import pytest
def test_setup():
assert run(setup).name == "prod"
这让我在 _pytest/nose.py
中出现错误:
def call_optional(obj,name):
method = getattr(obj,name,None)
isfixture = hasattr(method,"_pytestfixturefunction")
if method is not None and not isfixture and callable(method):
# If there's any problems allow the exception to raise rather than
# silently ignoring them
> method()
E TypeError: setup() missing 1 required positional argument: 'config'
我幼稚的猜测是 pytest
认为 setup
是一个测试方法,因此当我将它作为可调用参数传递给 run()
时尝试调用它,但失败了,因为我们'不要向它传递任何参数。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)