Best Python code snippet using molecule_python
test_testaid_unit_moleculeenv.py
Source:test_testaid_unit_moleculeenv.py
...3from testaid.moleculeenv import MoleculeEnv4def test_testaid_unit_moleculeenv_is_not_none(moleculeenv):5 assert moleculeenv is not None6 assert moleculeenv.get_roles() == list()7def test_testaid_unit_moleculeenv_get_molecule_ephemeral_directory(8 moleculeenv,9 monkeypatch):10 med = moleculeenv.get_molecule_ephemeral_directory()11 assert med == moleculeenv._molecule_ephemeral_directory12def test_testaid_unit_moleculeenv_get_molecule_scenario_directory(13 moleculeenv,14 monkeypatch):15 msd = moleculeenv.get_molecule_scenario_directory()16 assert msd == moleculeenv._molecule_scenario_directory17def test_testaid_unit_moleculeenv_get_roles(18 moleculeenv,19 monkeypatch,20 tmp_path):21 my_roles = ['my_role_1', 'my_role_2']22 roles_dir = tmp_path / 'roles'23 roles_dir.mkdir()24 my_role_1 = roles_dir / 'my_role_1'...
plugin.py
Source:plugin.py
...133@pytest.fixture(scope='session')134def moleculelog():135 return MoleculeLog()136@pytest.fixture(scope='session')137def molecule_ephemeral_directory(tmp_path_factory):138 '''environment variable MOLECULE_EPHEMERAL_DIRECTORY'''139 try:140 dir = Path(os.environ['MOLECULE_EPHEMERAL_DIRECTORY'])141 except KeyError:142 dir = tmp_path_factory.mktemp('molecule_ephemeral_directory')143 return dir144@pytest.fixture(scope='session')145def molecule_scenario_directory(tmp_path_factory):146 '''environment variable MOLECULE_SCENARIO_DIRECTORY'''147 try:148 dir = Path(os.environ['MOLECULE_SCENARIO_DIRECTORY'])149 except KeyError:150 dir = tmp_path_factory.mktemp('molecule_scenario_directory')151 return dir...
__init__.py
Source:__init__.py
1# -*- coding: utf-8 -*-2import os3import pytest4import testinfra5import testinfra.utils.ansible_runner6import yaml7from pathlib import Path8# https://medium.com/opsops/accessing-remote-host-at-test-discovery-stage-in-testinfra-pytest-7296235e804d9molecule_ephemeral_directory = os.environ.get('MOLECULE_EPHEMERAL_DIRECTORY')10if molecule_ephemeral_directory is None:11 raise RuntimeError(12 "[-] missing environment variable: 'MOLECULE_EPHEMERAL_DIRECTORY'"13 )14molecule_inventory_file = os.environ.get('MOLECULE_INVENTORY_FILE')15if molecule_inventory_file is None:16 raise RuntimeError(17 "[-] missing environment variable: 'MOLECULE_INVENTORY_FILE"18 )19def load_ansible_vars():20 """Load saved Ansible variables from `converge` stage."""21 ephemeral_directory = Path(molecule_ephemeral_directory)22 yaml_file = ephemeral_directory / 'ansible-vars.yml'23 ansible_vars = yaml.safe_load(yaml_file.read_bytes())24 print(f"[+] read runtime variables from '{yaml_file}'")25 return ansible_vars26ansible_vars = load_ansible_vars()27def in_roles(role, roles=None):28 """Return boolean for inclusion of role in a list of roles."""29 ansible_vars = load_ansible_vars()30 if roles is None:31 roles = ansible_vars.get('ansible_role_names', [])32 return role in roles33def skip_unless_role(role):34 """Decorator for skipping tests when related role is not involved."""35 if in_roles(role):36 return lambda func: func37 return pytest.mark.skipif(38 not in_roles(role),39 reason=f'role {role} only'40 )41def get_homedir(host=None, user=None):42 """Get user's home directory path in instance."""43 cmd = host.run(f'/usr/bin/getent passwd {user}')44 return cmd.stdout.split(':')[5]45def get_testinfra_hosts():46 """Get list of testinfra hosts."""47 testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(48 molecule_inventory_file49 ).get_hosts('all')50 print(f"[+] found testinfra_hosts: {testinfra_hosts}")51 # except RuntimeError:52 # print(f"[-] failed to get testinfra_hosts")53 # testinfra_hosts = []54 return testinfra_hosts...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!