-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
testinfra conflicts with pytest-ansible #58
Comments
(testinfra command is an alias to py.test) Both pytest-ansible and testinfra are pytest plugins that define the same BTW, I think you can easily rewrite your pytest-ansible tests with testinfra with the Ansible module: https://testinfra.readthedocs.org/en/latest/modules.html#ansible ;) |
I'm using pytest-ansible to test custom modules and/or plugins, not the infrastructure itself (so it's not viable to just substitute it with testinfra). With testinfra I plan to rewrite all of my playbook's/role's unit tests (which are currently just special ansible playbooks) and expand infrastructure tests, if we can get it to work alongside pytest-ansible. Let me know if I can help with anything. |
As a workaround you can add |
Is this still a valid issue? #58 (comment) seems like a fine solution. That pytest-ansible package hasn't seen a release for quite some time ... wondering if this is relevant anymore. |
pytest-ansible had 5 releases in 2023. |
I'm having a similar issue for a different arg - any ideas what I need to do?
EDIT: Solved this via this stackoverflow answer: https://stackoverflow.com/a/65356704 Running
|
I've hit this issue too, and thanks to all the people that contributed to this thread I was able to achieve a solution, sharing it in case it is useful to someone else. My problemUsing pytest-molecule for testing ansible roles in a monorepo, where each role is tested using molecule + testinfra. This is an example layout
In September pytest-molecule was archived, and the path forward is pytest-ansible, so the goal is to move to that one. But we couldn't move since pytest-ansible and pytest-testinfra got the conflict described in this issue. SolutionGet each molecule test to ignore pytest ansible. # molecule.yaml
...
verifier:
name: testinfra
options:
# pytest-ansible conflicts with --connection
p: "no:pytest-ansible"
# avoid loading global pyproject.toml options, so we don't
# load the setting that says "disable testinfra"
c: "." At the top level, ignore # pyproject.toml
[tool.pytest.ini_options]
norecursedirs="molecule"
# testinfra and pytest-ansible conflict as pytest
# plugins. We disable testinfra when running "all" tests,
# and disable `pytest-ansible` when running each molecule test
addopts = "-p no:pytest11.testinfra" Finally follow this guide so all molecule tests are loaded when running pytest. # tests/test_molecule.py
"""Tests for molecule scenarios."""
from __future__ import absolute_import, division, print_function
from pytest_ansible.molecule import MoleculeScenario
def test_integration(molecule_scenario: MoleculeScenario) -> None:
"""Run molecule for each scenario.
:param molecule_scenario: The molecule scenario object
"""
proc = molecule_scenario.test()
assert proc.returncode == 0 Results
Edit: I've published this to a repo in case more details are needed |
I ran into this over a year ago, but didn't have enough time to produce two documented PRs for the concurrent changes to both repos. I think The TL;DR, both modules try to use the same command line options. My solution was to preface each option with a string specific to each module to deconflict. You can see the changes here: ansible/pytest-ansible@main...davedittrich:pytest-ansible:develop main...davedittrich:pytest-testinfra:develop If someone else has time to resolve this, that would be great. :) |
When both testinfra and pytest-ansible are installed, testinfra fails with the following output:
Removing
--ansible-inventory
from the command line does not change the output. Uninstalling pytest-ansible and running testinfra fixes the issue, but leaves my tests which use it broken.Contents of
test_proxy.py
:Environment:
Python 2.7.11
pip 7.1.2
ansible 1.9.4
configured module search path = None
virtualenv 13.1.2
testinfra 1.0.1
pytest-ansible 1.3.1
pytest 2.8.4
The text was updated successfully, but these errors were encountered: