pytest - Pytest BDD:尝试使用场景装饰器时“TypeError:'NoneType'对象不可调用”
问题描述
我有许多具有相同功能文件格式的测试,但传递不同的参数并断言不同的 json 响应,所以我想scenarios
在scenario
. 我尝试使用的装饰器是:
@scenarios("../../features/errors.feature")
当我尝试使用时,scenarios
我收到以下错误,我无法真正找出问题所在:
==================================== ERRORS ====================================
_______ ERROR collecting functional/tests/test_api/test_api_error.py ________
src/test/functional/tests/test_api/test_api_error.py:17: in <module>
def get_data(v4_auth, get_url, from_date, to_date):
E TypeError: 'NoneType' object is not callable
=========================== short test summary info ============================
ERROR src/test/functional/tests/test_api/test_api_error.py - TypeError: 'N...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.11s ===============================
如果我使用scenario
装饰器并为功能文件中的每个场景提供一个带有 pass 的存根方法,那么这可以正常工作,但现在我有很多本质上冗余的函数来声明场景。
例如:
@scenario(
"../../features/error.feature",
"Retrieve data with an invalid from date format",
)
def invalid_from_date():
pass
@scenario(
"../../features/errors.feature",
"Retrieve data with an invalid to date format",
)
def invalid_to_date():
pass
@scenario(
"../../features/errors.feature",
"Retrieve data with all invalid params",
)
def invalid_params():
pass
使用scenario
装饰器时,所有装置都可以正常工作并且测试全部通过,我认为从阅读文档中我需要做的就是使用scenarios
装饰器来代替它。
它所在的行始终是它尝试调用的第一个函数的声明。
解决方案
推荐阅读
- javascript - 从 Postman 中的 JSON 响应中提取名称包含“-”的字段
- android - 如何在 Kotlin 中将字符串文字中的变量相乘?
- excel - 如何在excel单元格或单词中只保留一个空格
- javascript - TypeError:instance.render 不是 React 中的函数
- sql - SQL - 在时间间隔内搜索分区的动态最小日期
- javascript - 我可以手动下载 Tauri 构建依赖项吗?
- python - Pandas - 根据数据框绘制数据框的索引
- pytorch - 自回归变压器和非自回归变压器之间的区别仅仅是解码器中的注意力掩码吗?
- string - 如何在同一字符的两次出现之间打印行?
- rxjs - Angular 9/rxjs:如何处理 switchMap 中抛出的错误?