【问题标题】:Pytest-bdd - Fixture 'self' not foundPytest-bdd - 找不到夹具'self'
【发布时间】:2020-12-17 03:26:27
【问题描述】:

我正在使用 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 pytest-bdd


    【解决方案1】:

    这是因为 pytest 无法知道它是 self(就类实例而言)还是fixture。

    当您从 unittest.TestCase 继承您的类时,此问题已修复。 含义而不是您指定的class Recon_Tests() class ReconTests(unittest.TestCase).

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2016-07-27
      • 1970-01-01
      • 2021-10-01
      • 2021-03-13
      相关资源
      最近更新 更多