首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pytest-bdd - Fixture 'self‘未找到

Pytest-bdd - Fixture 'self‘未找到
EN

Stack Overflow用户
提问于 2020-08-28 15:51:31
回答 1查看 143关注 0票数 0

我正在使用pytest-bdd

这是我的功能文件

#recon_test.feature

代码语言:javascript
复制
Feature: This is used to run recon
  
 Scenarios:Run Recon

测试文件‘python #recon_test.py

代码语言:javascript
复制
Class Recon_Tests():

 @scenario('recon_test.feature','Run Recon')
 def test_run_recon(self):
  #do something
代码语言:javascript
复制
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():

经过

代码语言:javascript
复制

来避免这种情况,错误就消失了。

但是它给出了另一个错误,指出'Recon_Tests‘没有属性配置。

因为bdd试图读取fixture的配置对象以获取测试前钩子。

请给出建议

EN

回答 1

Stack Overflow用户

发布于 2021-07-26 21:49:57

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

当你从unittest.TestCase继承你的类时,这个问题就被修复了。这意味着您可以指定class ReconTests(unittest.TestCase)而不是class Recon_Tests()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63629643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档