pytest-bdd: Regression: KeyError in replacer
With #445, I’m seeing many tracebacks like this in my tests:
______________________ test_inserting_text_into_a_text_field_at_specific_position _______________________
request = <FixtureRequest for <Function test_inserting_text_into_a_text_field_at_specific_position>>
_pytest_bdd_example = {}
@pytest.mark.usefixtures(*args)
def scenario_wrapper(request, _pytest_bdd_example):
> scenario = templated_scenario.render(_pytest_bdd_example)
.tox/bleeding/lib/python3.9/site-packages/pytest_bdd/scenario.py:173:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/bleeding/lib/python3.9/site-packages/pytest_bdd/parser.py:249: in render
steps = [
.tox/bleeding/lib/python3.9/site-packages/pytest_bdd/parser.py:251: in <listcomp>
name=templated_step.render(context),
.tox/bleeding/lib/python3.9/site-packages/pytest_bdd/parser.py:364: in render
return STEP_PARAM_RE.sub(replacer, self.name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
m = <re.Match object; span=(18, 24), match='<Home>'>
def replacer(m: typing.Match):
varname = m.group(1)
> return str(context[varname])
E KeyError: 'Home'
.tox/bleeding/lib/python3.9/site-packages/pytest_bdd/parser.py:362: KeyError
There are many other such failures, but this one is from this scenario:
Scenario: Inserting text into a text field at specific position
When I open data/paste_primary.html
And I insert "one two three four" into the text field
And I run :click-element id qute-textarea
And I wait for "Entering mode KeyMode.insert (reason: clicking input)" in the log
# Move to the beginning and two characters to the right
And I press the keys "<Home>"
And I press the key "<Right>"
And I press the key "<Right>"
And I run :insert-text Hello world
# Compare
Then the javascript message "textarea contents: onHello worlde two three four" should be logged
specifically, the And I press the keys "<Home>"
line there.
The underlying Python code is simple:
@bdd.when(bdd.parsers.re('I press the keys? "(?P<keys>[^"]*)"'))
def press_keys(quteproc, keys):
"""Send the given fake keys to qutebrowser."""
quteproc.press_keys(keys)
Scenario: :selection-follow with link tabbing (without JS)
When I set content.javascript.enabled to false
And I run :mode-leave
And I run :jseval document.activeElement.blur();
And I run :fake-key <tab>
And I run :selection-follow
Then data/hello.txt should be loaded
with this code:
@bdd.when(bdd.parsers.parse("I run {command}"))
def run_command(quteproc, server, tmpdir, command):
# ...
results in a KeyError: tab
. In other words, it seems like anything in <...>
in a scenario now seems to be parsed in some special way.
I’ve tried to write a reproducer:
bug.feature:
Feature: Reproducer
Scenario: Pressing keys
When I run :fake-key <Ctrl+c>
And I run :fake-key <tab>
test_bug.py:
import pytest_bdd as bdd
bdd.scenarios('bug.feature')
@bdd.when(bdd.parsers.parse("I run {command}"))
def run_command(command):
pass
but unfortunately, I can not reproduce the issue there. Any ideas what could be going wrong there?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (10 by maintainers)
Commits related to this issue
- requirements: Revert to pytest-bdd release for bleeding See https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to qutebrowser/qutebrowser by The-Compiler 3 years ago
- Avoid pytest-bdd 5 for now See https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to qutebrowser/qutebrowser by The-Compiler 3 years ago
- requirements: Revert to pytest-bdd release for bleeding See https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to mkonig/qutebrowser by The-Compiler 3 years ago
- Avoid pytest-bdd 5 for now See https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to mkonig/qutebrowser by The-Compiler 3 years ago
- Ignore </> in step parameter values closes #447 — committed to jirikuncar/pytest-bdd by jirikuncar 3 years ago
- Mute pytest-bdd test due to https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to skhomuti/allure-python by skhomuti 2 years ago
- Require "Scenario Outline" keyword for outlined scenario. This should fix https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to pytest-dev/pytest-bdd by youtux 2 years ago
- [pyqt6] tests: downgrade pytest-bdd to 4.1.0 https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to tinywrkb/org.qutebrowser.qutebrowser by tinywrkb 2 years ago
- [pyqt6] tests: downgrade pytest-bdd to 4.1.0 https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to tinywrkb/org.qutebrowser.qutebrowser by tinywrkb 2 years ago
- tests: downgrade pytest-bdd to 4.1.0 https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to tinywrkb/org.qutebrowser.qutebrowser by tinywrkb 2 years ago
- tests: Downgrade pytest-bdd to 4.1.0 https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to tinywrkb/org.qutebrowser.qutebrowser by tinywrkb 2 years ago
- requirements: Revert to pytest-bdd release for bleeding See https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to twigleingrid/qutebrowser by The-Compiler 3 years ago
- Avoid pytest-bdd 5 for now See https://github.com/pytest-dev/pytest-bdd/issues/447 — committed to twigleingrid/qutebrowser by The-Compiler 3 years ago
- requirements: Upgrade to pytest-bdd 6.0.0 https://github.com/pytest-dev/pytest-bdd/issues/447 has been fixed — committed to qutebrowser/qutebrowser by The-Compiler 2 years ago
I’m fixing this in https://github.com/pytest-dev/pytest-bdd/pull/524 by parsing the params in angular brackets only for
Scenario Outline
s. NormalScenario
s will treat them verbatim.