Pytest-bdd - Fixture 'self' not found

494 Views Asked by At

i am using pytest-bdd

Here is my feature file

#recon_test.feature

Feature: This is used to run recon
  
 Scenarios:Run Recon

Test File '''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

to avoid this , and the error is gone .

But it gives another error saying that 'Recon_Tests' does not have an attribute config.

as bdd tries to read the fixture's config object for pre test hooks.

Please suggest

1

There are 1 best solutions below

0
On

This is because pytest has no way of knowing whether it is a self (in terms of class instance) or a fixture.

This is fixed when you inherit your class from unittest.TestCase. Meaning instead of class Recon_Tests() you specify class ReconTests(unittest.TestCase).