Skip to content
Latchkey

Molecule "verify" step failed (testinfra / ansible verifier) in CI

After idempotence, Molecule runs the verifier to assert the instance reached the expected state. With the testinfra verifier this runs pytest tests; with the ansible verifier it runs verify.yml. A failed assertion, or a missing verifier dependency, fails the step.

What this error means

Molecule fails at verify with pytest assertion output ("assert False") or "pytest: command not found" / "No module named pytest_testinfra", or a failed assert in verify.yml.

Molecule
def test_nginx_running(host):
>       assert host.service("nginx").is_running
E       assert False
CRITICAL Verifier failed with return code 1

Common causes

The asserted state does not match reality

A testinfra assertion (a service running, a file present, a port listening) does not hold, because the role did not achieve it or the test expects the wrong thing.

The verifier dependency is not installed

The testinfra verifier needs pytest-testinfra. Without it, verify fails with a missing-module or command-not-found error rather than an assertion.

How to fix it

Install the verifier dependency

Install pytest-testinfra so the testinfra verifier can run.

Terminal
pip install pytest-testinfra

Align the assertion with the converged state

  1. Read which assertion failed in the verify output.
  2. Fix the role so the state holds, or correct an over-strict test.
  3. Re-run molecule verify after a converge to iterate.
molecule/default/tests/test_default.py
# molecule/default/tests/test_default.py
def test_nginx_running(host):
    svc = host.service("nginx")
    assert svc.is_running
    assert svc.is_enabled

How to prevent it

  • Pin pytest-testinfra in test requirements when using the testinfra verifier.
  • Keep assertions in step with what the role guarantees.
  • Run molecule verify after converge during development.

Frequently asked questions

What causes ""verify" step failed"?
A testinfra assertion (a service running, a file present, a port listening) does not hold, because the role did not achieve it or the test expects the wrong thing.
How do I fix "verify" step failed?
Install pytest-testinfra so the testinfra verifier can run.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card