Best Python code snippet using molecule_python
test_command.py
Source: test_command.py
1import os2import pytest3import sh4from molecule.scenario import ephemeral_directory5@pytest.fixture6def scenario_to_test(request):7 return request.param8@pytest.fixture9def scenario_name(request):10 try:11 return request.param12 except AttributeError:13 return None14@pytest.fixture15def driver_name(request):16 return request.param17@pytest.mark.parametrize(18 "scenario_to_test, driver_name, scenario_name",19 [("driver/hetznercloud", "hetznercloud", "default")],20 indirect=["scenario_to_test", "driver_name", "scenario_name"],21)22def test_command_check(scenario_to_test, with_scenario, scenario_name):23 options = {"scenario_name": scenario_name}24 cmd = sh.molecule.bake("check", **options)25 pytest.helpers.run_command(cmd)26@pytest.mark.parametrize(27 "scenario_to_test, driver_name, scenario_name",28 [("driver/hetznercloud", "hetznercloud", "default")],29 indirect=["scenario_to_test", "driver_name", "scenario_name"],30)31def test_command_cleanup(scenario_to_test, with_scenario, scenario_name):32 options = {"scenario_name": scenario_name}33 cmd = sh.molecule.bake("cleanup", **options)34 pytest.helpers.run_command(cmd)35@pytest.mark.parametrize(36 "scenario_to_test, driver_name, scenario_name",37 [("driver/hetznercloud", "hetznercloud", "default")],38 indirect=["scenario_to_test", "driver_name", "scenario_name"],39)40def test_command_converge(scenario_to_test, with_scenario, scenario_name):41 options = {"scenario_name": scenario_name}42 cmd = sh.molecule.bake("converge", **options)43 pytest.helpers.run_command(cmd)44@pytest.mark.parametrize(45 "scenario_to_test, driver_name, scenario_name",46 [("driver/hetznercloud", "hetznercloud", "default")],47 indirect=["scenario_to_test", "driver_name", "scenario_name"],48)49def test_command_create(scenario_to_test, with_scenario, scenario_name):50 options = {"scenario_name": scenario_name}51 cmd = sh.molecule.bake("create", **options)52 pytest.helpers.run_command(cmd)53@pytest.mark.skip(54 reason="Disabled due to https://github.com/ansible/galaxy/issues/2030"55)56@pytest.mark.parametrize(57 "scenario_to_test, driver_name, scenario_name",58 [("dependency", "hetznercloud", "ansible-galaxy")],59 indirect=["scenario_to_test", "driver_name", "scenario_name"],60)61def test_command_dependency_ansible_galaxy(62 request, scenario_to_test, with_scenario, scenario_name63):64 options = {"scenario_name": scenario_name}65 cmd = sh.molecule.bake("dependency", **options)66 pytest.helpers.run_command(cmd)67 dependency_role = os.path.join(68 ephemeral_directory("molecule"),69 "dependency",70 "ansible-galaxy",71 "roles",72 "timezone",73 )74 assert os.path.isdir(dependency_role)75@pytest.mark.parametrize(76 "scenario_to_test, driver_name, scenario_name",77 [("dependency", "hetznercloud", "gilt")],78 indirect=["scenario_to_test", "driver_name", "scenario_name"],79)80def test_command_dependency_gilt(81 request, scenario_to_test, with_scenario, scenario_name82):83 options = {"scenario_name": scenario_name}84 cmd = sh.molecule.bake("dependency", **options)85 pytest.helpers.run_command(cmd)86 dependency_role = os.path.join(87 ephemeral_directory("molecule"), "dependency", "gilt", "roles", "timezone"88 )89 assert os.path.isdir(dependency_role)90@pytest.mark.parametrize(91 "scenario_to_test, driver_name, scenario_name",92 [("dependency", "hetznercloud", "shell")],93 indirect=["scenario_to_test", "driver_name", "scenario_name"],94)95def test_command_dependency_shell(96 request, scenario_to_test, with_scenario, scenario_name97):98 options = {"scenario_name": scenario_name}99 cmd = sh.molecule.bake("dependency", **options)100 pytest.helpers.run_command(cmd)101 dependency_role = os.path.join(102 ephemeral_directory("molecule"), "dependency", "shell", "roles", "timezone"103 )104 assert os.path.isdir(dependency_role)105@pytest.mark.parametrize(106 "scenario_to_test, driver_name, scenario_name",107 [("driver/hetznercloud", "hetznercloud", "default")],108 indirect=["scenario_to_test", "driver_name", "scenario_name"],109)110def test_command_destroy(scenario_to_test, with_scenario, scenario_name):111 options = {"scenario_name": scenario_name}112 cmd = sh.molecule.bake("destroy", **options)113 pytest.helpers.run_command(cmd)114@pytest.mark.parametrize(115 "scenario_to_test, driver_name, scenario_name",116 [("driver/hetznercloud", "hetznercloud", "default")],117 indirect=["scenario_to_test", "driver_name", "scenario_name"],118)119def test_command_idempotence(scenario_to_test, with_scenario, scenario_name):120 pytest.helpers.idempotence(scenario_name)121@pytest.mark.parametrize("driver_name", [("hetznercloud")], indirect=["driver_name"])122def test_command_init_role(temp_dir, driver_name, skip_test):123 pytest.helpers.init_role(temp_dir, driver_name)124@pytest.mark.parametrize("driver_name", [("hetznercloud")], indirect=["driver_name"])125def test_command_init_scenario(temp_dir, driver_name, skip_test):126 pytest.helpers.init_scenario(temp_dir, driver_name)127@pytest.mark.parametrize(128 "scenario_to_test, driver_name, scenario_name",129 [("driver/hetznercloud", "hetznercloud", "default")],130 indirect=["scenario_to_test", "driver_name", "scenario_name"],131)132def test_command_lint(scenario_to_test, with_scenario, scenario_name):133 options = {"scenario_name": scenario_name}134 cmd = sh.molecule.bake("lint", **options)135 pytest.helpers.run_command(cmd)136@pytest.mark.parametrize(137 "scenario_to_test, driver_name, expected",138 [139 (140 "driver/hetznercloud",141 "hetznercloud",142 """143Instance Name Driver Name Provisioner Name Scenario Name Created Converged144--------------- ------------- ------------------ --------------- --------- -----------145instance hetznercloud ansible default false false146instance-1 hetznercloud ansible multi-node false false147instance-2 hetznercloud ansible multi-node false false148""".strip(), # noqa149 )150 ],151 indirect=["scenario_to_test", "driver_name"],152)153def test_command_list(scenario_to_test, with_scenario, expected):154 pytest.helpers.list(expected)155@pytest.mark.parametrize(156 "scenario_to_test, driver_name, expected",157 [158 (159 "driver/hetznercloud",160 "hetznercloud",161 """162instance hetznercloud ansible default false false163instance-1 hetznercloud ansible multi-node false false164instance-2 hetznercloud ansible multi-node false false165""".strip(),166 ) # noqa167 ],168 indirect=["scenario_to_test", "driver_name"],169)170def test_command_list_with_format_plain(scenario_to_test, with_scenario, expected):171 pytest.helpers.list_with_format_plain(expected)172@pytest.mark.parametrize(173 "scenario_to_test, driver_name, login_args, scenario_name",174 [175 (176 "driver/hetznercloud",177 "hetznercloud",178 [["instance-1", ".*instance-1.*"], ["instance-2", ".*instance-2.*"]],179 "multi-node",180 )181 ],182 indirect=["scenario_to_test", "driver_name", "scenario_name"],183)184def test_command_login(scenario_to_test, with_scenario, login_args, scenario_name):185 pytest.helpers.login(login_args, scenario_name)186@pytest.mark.parametrize(187 "scenario_to_test, driver_name, scenario_name",188 [("driver/hetznercloud", "hetznercloud", "default")],189 indirect=["scenario_to_test", "driver_name", "scenario_name"],190)191def test_command_prepare(scenario_to_test, with_scenario, scenario_name):192 options = {"scenario_name": scenario_name}193 cmd = sh.molecule.bake("create", **options)194 pytest.helpers.run_command(cmd)195 cmd = sh.molecule.bake("prepare", **options)196 pytest.helpers.run_command(cmd)197@pytest.mark.parametrize(198 "scenario_to_test, driver_name, scenario_name",199 [("driver/hetznercloud", "hetznercloud", "default")],200 indirect=["scenario_to_test", "driver_name", "scenario_name"],201)202def test_command_side_effect(scenario_to_test, with_scenario, scenario_name):203 options = {"scenario_name": scenario_name}204 cmd = sh.molecule.bake("side-effect", **options)205 pytest.helpers.run_command(cmd)206@pytest.mark.parametrize(207 "scenario_to_test, driver_name, scenario_name",208 [("driver/hetznercloud", "hetznercloud", "default")],209 indirect=["scenario_to_test", "driver_name", "scenario_name"],210)211def test_command_syntax(scenario_to_test, with_scenario, scenario_name):212 options = {"scenario_name": scenario_name}213 cmd = sh.molecule.bake("syntax", **options)214 pytest.helpers.run_command(cmd)215@pytest.mark.parametrize(216 "scenario_to_test, driver_name, scenario_name",217 [("driver/hetznercloud", "hetznercloud", None)],218 indirect=["scenario_to_test", "driver_name", "scenario_name"],219)220def test_command_test(scenario_to_test, with_scenario, scenario_name, driver_name):221 pytest.helpers.test(driver_name, scenario_name)222@pytest.mark.parametrize(223 "scenario_to_test, driver_name, scenario_name",224 [("driver/hetznercloud", "hetznercloud", "default")],225 indirect=["scenario_to_test", "driver_name", "scenario_name"],226)227def test_command_verify(scenario_to_test, with_scenario, scenario_name):...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
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!!