0

I'm learning pytest and I get an error trying to run a test that worked fine before I added pytest-bdd(feature file, step file is the one I'm trying to run) This is my code:

import pytest
import time
from selenium import webdriver
from pytest_bdd import scenario, given, when, then

@scenario('../feature/learn.feature', 'learning pytest-bdd')

@when('Does work-->website open, find element')
def does_work():
    driver = webdriver.Edge(r"C:/Users/artri/Downloads/edgedriver_win64/msedgedriver.exe")

    driver.get('https://www.example.com/')
    driver.maximize_window()
    print(driver.title)

    time.sleep(5)

    element = driver.find_element_by_xpath("//button[@class='btn btn-outline-light btn-lg btn-close']")
    element.click()

    name = driver.find_element_by_xpath("//a[@href='/items/something/']").text
    driver.quit()

    return name

@then('Get text "something"')
def test_work():
    assert does_work() == 'something'

It finds the element and checks if it's value is right. I would like to know why after adding steps and making the feature file it doesn't work. Other test in the same steps file works just like they did before. The error massage:

@then('Get text "something"')
    def test_work():
>       assert does_work() == 'something'
E       TypeError: scenario_wrapper() missing 1 required positional argument: 'request'

I looked at a couple similar questions, but non were understandable for me. If anyone has any idea where the issue might be or some links would be very appreciated!

Artis
  • 35
  • 5
  • I got rid of the TypeError by commenting the @scenario line but I don’t think it’s the way to do it right – Artis Jul 14 '21 at 10:45

1 Answers1

1

You have decorator without function def.

From documentation at: https://github.com/pytest-dev/pytest-bdd

@scenario('publish_article.feature', 'Publishing the article')
def test_publish():
    pass

You need to decorate empty function.