首页 > 解决方案 > 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 尝试读取夹具的配置对象以获取预测试挂钩时。

请建议

标签: pytestpytest-bdd

解决方案


这是因为 pytest 无法知道它是自我(就类实例而言)还是固定装置。

当您从unittest.TestCase. 含义而不是class Recon_Tests()您指定 class ReconTests(unittest.TestCase).


推荐阅读