Skip to content

Commit

Permalink
Avoid plugin misaactivation with random ansible_ prefixed fixtures
Browse files Browse the repository at this point in the history
Fixes a bug where a randomly named fixture caused plugin activation
even if the project would not make any use of pytest-ansible, causing
a runtime error due to the assertion of missing arguments.
  • Loading branch information
ssbarnea committed Oct 20, 2023
1 parent 8e31a8f commit 5154f7e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
72 changes: 37 additions & 35 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
Barroso
Laska
NOTESTSCOLLECTED
Rominger
TESTSFAILED
USAGEERROR
VIRSH
addini
addinivalue_line
addoption
argparsing
autouse
caplog
cidrblock
codecov
errlines
filterwarnings
pathsep
pytest
setenv
setuptools
startpath
metafunc
testpaths
udring
webservers
addoption
Rominger
Barroso
Laska
runas
runtask
pluginmanager
modifyitems
fixturedefs
fixtureinfo
fixturenames
fspath
funcargs
getfixturevalue
getplugin
pytestmark
autouse
rootpath
VIRSH
pytester
getgroup
addini
addinivalue_line
getplugin
lineinfile
makepyfile
metafunc
modifyitems
pandoc
funcargs
parseoutcomes
pathsep
pluginmanager
pytest
pytester
pytestmark
pytrace
reportinfo
fspath
NOTESTSCOLLECTED
TESTSFAILED
USAGEERROR
makepyfile
runpytest_subprocess
parseoutcomes
rootpath
runas
runpytest
errlines
codecov
runpytest_subprocess
runtask
setenv
setuptools
startpath
testpaths
udring
webservers
14 changes: 9 additions & 5 deletions src/pytest_ansible/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,15 @@ def pytest_collection_modifyitems(self, session, config, items):
for item in items:
if not hasattr(item, "fixturenames"):
continue
if any(fixture.startswith("ansible_") for fixture in item.fixturenames):
marker = item.get_closest_marker("ansible")
if marker is None:
uses_ansible_fixtures = True
break

for fixture_name in item.fixturenames:
if not fixture_name.startswith("ansible_"):
continue
# ignore any normal fixtures that have definitions to avoid miss activations
if fixture_name in item._fixtureinfo.name2fixturedefs:
continue
uses_ansible_fixtures = True
break

if uses_ansible_fixtures:
# assert required --ansible-* parameters were used
Expand Down

0 comments on commit 5154f7e

Please sign in to comment.