question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty step pattern is giving "Cannot find step definition" when specified at the end of a step sentence

See original GitHub issue

I am using Python 2.7.10, MacOS Sierra version 10.12.4 and Radish-BDD version 0.4.1

With the feature file of:

Feature: A test feature for issues with tags specified after a scenario outline examples table
  A feature description here

  Scenario: Fruit Consumption 2
    Given I have a appple
    When I eat the apple
    Then I get lots of fiber

steps.py contents:

from radish import given, when, then


@given('I have a {}')
def my_step(step, fruit):
    pass


@when('I {} the {}')
def my_step(step, method, fruit):
    pass


@then('I get lots of {}')
def my_setp(step, what):
    pass

Then:

Error: Cannot find step definition for step 'Given I have a apple' in tests/stuff/features/stuff.feature:13

Error Oracle says:
There is no step defintion for 'Given I have a apple'.
All steps should be declared in a module located in tests/stuff.
For example you could do:

@step(r"Given I have a apple")
def my_step(step):
    raise NotImplementedError("This step is not implemented yet")

A workaround for using empty step patterns is (Adding something like a period or word after the {}):

NOTE: Your scenario sentences in your feature file will require adding the . or word to the end of the sentence also.

@step(r'I have a {}.')
def my_step(step, user):
    pass


@when(r'I {} the {}.')
def my_step(step, method, fruit):
    pass


@then(r'I get lots of {}.')
def my_step(step, what):
    pass

An alternative work-around is to use regexes as such:

import re

from radish import given, when, then


@given(re.compile(r'I have a (.+)'))
def my_step(step, fruit):
    pass


@when(re.compile(r'I (.+?) the (.+)'))
def my_step(step, method, fruit):
    pass


@then(re.compile(r'I get lots of (.+)'))
def my_step(step, what):
    pass

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
timofurrercommented, May 6, 2017

I’ve created an issue in the parse project: https://github.com/r1chardj0n3s/parse/issues/41

1reaction
rscrimojrcommented, May 5, 2017

Looking at the radish source code. In matcher.py I see that this may be a bug in the third-party library parse

On second thought, parse looks fine:

Python 2.7.10 (default, Feb  6 2017, 23:53:20)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import parse
>>> parse.__version__
'1.8.0'
>>> parse.parse('I have a {}', 'I have a apple')
<Result ('apple',) {}>
>>>

However, this gives as interesting outcome:

>>> patt = parse.compile('I have a {}')
>>> patt.search('I have a apple')
<Result ('a',) {}>
>>> patt.parse('I have a apple')
<Result ('apple',) {}>

and

>>> patt = parse.compile('I {} a {}')
>>> patt.parse('I have a apple')
<Result ('have', 'apple') {}>
>>> patt.search('I have a apple')
<Result ('have', 'a') {}>

Looks like search() is giving a weird result, parse() looks correct.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Step Definitions - Cucumber Documentation
When Cucumber executes a Gherkin step in a scenario, it will look for a matching step definition to execute. To illustrate how this...
Read more >
Cucumber: Unable to find step definition - Stack Overflow
It looks like Cucumber isn't finding your step defintion class. In your unit test class you say: glue = {"com.macro.definition"}.
Read more >
Step Definition - Cucumber - Tools QA
A Step Definition is a small piece of code with a pattern attached to it or in other words a Step Definition is...
Read more >
A Practical Example of Cucumber's Step Definitions in Java
The step annotated with @Then assumes that the former step has been executed before, and it gets the userAlias variable value from the...
Read more >
Make your Word documents accessible to people with ...
This topic gives you step-by-step instructions and best practices on how to make your Word ... To find missing alt text, use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found