在测试中使用可调用对象时,Pytest/nose 会抛出错误“缺少所需的位置参数”

问题描述

我正在尝试使用 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...