Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsing of indented steps #379

Closed
UmBottesWillen opened this issue Jul 8, 2020 · 2 comments
Closed

Incorrect parsing of indented steps #379

UmBottesWillen opened this issue Jul 8, 2020 · 2 comments

Comments

@UmBottesWillen
Copy link

When indenting one And step definition after a Given step definition, pytest will incorrectly parse both steps as one.

Example - feature file:

Scenario: List all pizzas as restaurant user
  Given No pizza used in testing is in the database
    And I'm a restaurant user
    
  When I go to the pizza endpoint

  Then I should see a list of pizzas

The given example will trigger the following error when the file is parsed:

request = <FixtureRequest for <Function test_endpoint>>, step = <pytest_bdd.feature.Step object at 0x7f7ad9520d30>, 
scenario = <pytest_bdd.feature.Scenario object at 0x7f7ad9520e50>, encoding = 'utf-8'

    def _find_step_function(request, step, scenario, encoding):
        """Match the step defined by the regular expression pattern.
    
        :param request: PyTest request object.
        :param step: Step.
        :param scenario: Scenario.
    
        :return: Function of the step.
        :rtype: function
        """
        name = step.name
        try:
            # Simple case where no parser is used for the step
            return request.getfixturevalue(get_step_fixture_name(name, step.type, encoding))
        except pytest_fixtures.FixtureLookupError:
            try:
                # Could not find a fixture with the same name, let's see if there is a parser involved
                name = find_argumented_step_fixture_name(name, step.type, request._fixturemanager, request)
                if name:
                    return request.getfixturevalue(name)
                raise
            except pytest_fixtures.FixtureLookupError:
>               raise exceptions.StepDefinitionNotFoundError(
                    u"""Step definition is not found: {step}."""
                    """ Line {step.line_number} in scenario "{scenario.name}" in the feature "{feature.filename}""".format(
                        step=step, scenario=scenario, feature=scenario.feature
                    )
                )
E               pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found: Given "No pizza used in testing is in the database
E               And I'm a restaurant user". Line 11 in scenario "List all pizzas as restaurant user" in the feature "/usr/pizzaservice/test/service/api/v1/features/pizza_tests.feature

../local/lib/python3.8/site-packages/pytest_bdd/scenario.py:86: StepDefinitionNotFoundError

pip list output:

Package                       Version
----------------------------- -------------
apturl                           0.5.2
attrs                             19.3.0
bcrypt                          3.1.7
beautifulsoup4            4.8.2
blinker                       1.4
Brlapi                        0.7.0
cached-property               1.5.1
certifi                       2019.11.28
chardet                       3.0.4
checkbox-support              0.22
Click                         7.0
command-not-found             0.3
coverage                      5.0.3
cryptography                  2.8
cupshelpers                   1.0
dbus-python                   1.2.16
defer                         1.0.6
distro                        1.4.0
distro-info                   0.23ubuntu1
docker                        4.1.0
docker-compose                1.25.0
dockerpty                     0.4.1
docopt                        0.6.2
duplicity                     0.8.12.0
entrypoints                   0.3
fastapi                       0.48.0
fasteners                     0.14.1
feedparser                    5.2.1
Flask                         1.1.2
Flask-SQLAlchemy              2.4.1
future                        0.18.2
glob2                         0.7
guacamole                     0.9.2
h11                           0.9.0
html5lib                      1.0.1
httplib2                      0.14.0
httptools                     0.0.13
idna                          2.9
importlib-metadata            1.5.0
itsdangerous                  1.1.0
Jinja2                        2.10.1
jsonschema                    3.2.0
keyring                       18.0.1
keyrings.alt                  3.4.0
language-selector             0.1
launchpadlib                  1.10.13
lazr.restfulclient            0.14.2
lazr.uri                      1.0.3
lockfile                      0.12.2
louis                         3.12.0
lxml                          4.5.0
macaroonbakery                1.3.1
Mako                          1.1.2
MarkupSafe                    1.1.1
monotonic                     1.5
more-itertools                8.2.0
mypy                          0.761
mypy-extensions               0.4.3
netifaces                     0.10.4
oauthlib                      3.1.0
olefile                       0.46
onboard                       1.4.1
packaging                     20.1
padme                         1.1.1
paramiko                      2.6.0
parse                         1.15.0
parse-type                    0.5.2
pexpect                       4.6.0
Pillow                        7.0.0
pip                           20.1.1
plainbox                      0.25
pluggy                        0.13.1
protobuf                      3.6.1
psycopg2                      2.8.5
py                            1.8.1
pyasn1                        0.4.2
pycairo                       1.16.2
pycrypto                      2.6.1
pycups                        1.9.73
pycurl                        7.43.0.2
pydantic                      1.4
PyGObject                     3.36.0
PyJWT                         1.7.1
pymacaroons                   0.13.0
PyNaCl                        1.3.0
pyparsing                     2.4.6
pyRFC3339                     1.1
pyrsistent                    0.15.5
python-apt                    2.0.0
python-dateutil               2.7.3
python-debian                 0.1.36ubuntu1
pytz                          2019.3
pyxdg                         0.26
PyYAML                        5.3.1
reportlab                     3.5.34
requests                      2.23.0
requests-unixsocket           0.2.0
SecretStorage                 2.3.1
setuptools                    45.2.0
simplejson                    3.16.0
six                           1.14.0
soupsieve                     1.9.5
SQLAlchemy                    1.3.16
ssh-import-id                 5.10
starlette                     0.12.9
system-service                0.3
systemd-python                234
texttable                     1.6.2
typed-ast                     1.4.1
typing-extensions             3.7.4.1
ubuntu-advantage-tools        20.3
ubuntu-drivers-common         0.0.0
ufw                           0.36
unattended-upgrades           0.1
unity-scope-calculator        0.1
unity-scope-chromiumbookmarks 0.1
unity-scope-colourlovers      0.1
unity-scope-devhelp           0.1
unity-scope-firefoxbookmarks  0.1
unity-scope-manpages          0.1
unity-scope-openclipart       0.1
unity-scope-texdoc            0.1
unity-scope-tomboy            0.1
unity-scope-virtualbox        0.1
unity-scope-yelp              0.1
unity-scope-zotero            0.1
urllib3                       1.25.8
usb-creator                   0.3.7
uvicorn                       0.11.2
uvloop                        0.14.0
wadllib                       1.3.3
wcwidth                       0.1.8
webencodings                  0.5.1
websocket-client              0.53.0
websockets                    8.1
Werkzeug                      1.0.1
wheel                         0.34.2
xdiagnose                     3.8.9
xkit                          0.0.0
XlsxWriter                    1.1.2
zipp                          1.0.0

PyTest version:

This is pytest version 5.4.2, imported from /usr/local/lib/python3.8/site-packages/pytest/__init__.py
setuptools registered plugins:
  pytest-bdd-3.3.0 at /usr/local/lib/python3.8/site-packages/pytest_bdd/plugin.py
  pytest-pgsql-1.1.2 at /usr/local/lib/python3.8/site-packages/pytest_pgsql/plugin.py
  pytest-cov-2.9.0 at /usr/local/lib/python3.8/site-packages/pytest_cov/plugin.py
  pytest-mock-2.0.0 at /usr/local/lib/python3.8/site-packages/pytest_mock/__init__.py

Operating system/IDE:

  • Ubuntu 20.04 LTS
  • PyCharm 2020.1.2 (Professional)
@RonnyPfannschmidt RonnyPfannschmidt transferred this issue from pytest-dev/pytest Jul 8, 2020
@jirikuncar
Copy link
Member

IMHO it can be resolved by using the official parser (see #378).

@youtux
Copy link
Contributor

youtux commented Sep 16, 2020

Closing as this is not valid gherkin syntax. When the official parser/new parser is going to be released, this syntax is not going to be allowed at all.

@youtux youtux closed this as completed Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants