'How to check set_fact in molecule?

I've created a simple task which creates a fact (new variable):

---
- name: Define internal user based on prefix
  set_fact:
    role_user_uid: "{{ lookup('vars', '{{ user_prefix }}_uid', default='') }}"

where user_prefix is defined in defaults/ as user_prefix: "ansible".

How can I create a test which checks that user_prefix has a specific value?

I've tried via testinfra

@pytest.fixture()
def AnsibleVars(host):
    all_vars = host.ansible.get_variables()
    return all_vars

def test_user_exists(host,AnsibleVars):
    print(AnsibleVars)
    var_prefix = AnsibleVars['user_prefix']

and via ansible provider:

- name: "test default user"
  assert:
    that:
      user_prefix == "ansible"

but I get errors that user_prefix is note defined.

I did enable gather_facts: yes in verify.yml



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source