pytest - Pytest-bdd - 未找到夹具“自我”
问题描述
我正在使用 pytest-bdd
这是我的功能文件
#recon_test.feature
Feature: This is used to run recon
Scenarios:Run Recon
测试文件'''python #recon_test.py
Class Recon_Tests():
@scenario('recon_test.feature','Run Recon')
def test_run_recon(self):
#do something
when i run this using command pytest , i get error **fixture 'self' not found.**
Because due to scenario annotation it treats this function as fixture maybe , and expects **'self'** to be another fixture.
I want to use the '@scenario' in my test functions inside the test classes . Is there any way ?
Also , i have found a workaround for this , i have created a fixture
```python
def self():
pass
避免这种情况,错误就消失了。
但它给出了另一个错误,说“Recon_Tests”没有属性配置。
当 bdd 尝试读取夹具的配置对象以获取预测试挂钩时。
请建议
解决方案
这是因为 pytest 无法知道它是自我(就类实例而言)还是固定装置。
当您从unittest.TestCase
. 含义而不是class Recon_Tests()
您指定
class ReconTests(unittest.TestCase)
.
推荐阅读
- python - 将变量动态分配给 pandas 函数
- android-studio - 错误:找不到用于签署配置“调试”的 android.debug.keystore'
- kotlin - Kotlin 中的 Dividing Doubles 返回 NaN
- r - 如何在不创建大量 nas 的情况下将价格(格式为“$xx.xx”)转换为数字格式?
- python - 我的 while 循环没有结束。为什么会这样?
- google-sheets - 仅当今天小于或等于 Google 表格中当月的最后一天时,如何计算今天的日期?
- ios - App Store Connect 上传错误“您没有获得云管理分发证书的访问权限”
- python - 为什么这个 pysimplegui 不能正常工作
- java - 类的方法没有给出预期的结果
- r - R中的基准矩阵函数和计算