0
0
Selenium Pythontesting~10 mins

Parallel execution in CI in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run tests in parallel using pytest.

Selenium Python
pytest.main(['-n', '[1]'])
Drag options to blanks, or click blank then click option'
A4
B0
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 disables parallelism.
Using 1 runs tests sequentially.
2fill in blank
medium

Complete the code to import the pytest-xdist plugin for parallel test execution.

Selenium Python
import [1]
Drag options to blanks, or click blank then click option'
Axdist
Bpytest_xdist
Cpytest_parallel
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the plugin name.
Importing a non-existent plugin.
3fill in blank
hard

Fix the error in the pytest command to enable parallel execution with 3 workers.

Selenium Python
pytest.main(['-n', '[1]'])
Drag options to blanks, or click blank then click option'
A'3'
B3
C'three'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an integer instead of a string.
Using words like 'three' instead of digits.
4fill in blank
hard

Fill both blanks to create a pytest fixture that runs setup and teardown for each test in parallel.

Selenium Python
@pytest.fixture(scope=[1])
def setup_teardown():
    print('Setup')
    yield
    print('Teardown')

# Use fixture in test
def test_example(setup_teardown):
    assert 1 == 1
Drag options to blanks, or click blank then click option'
A'session'
B'function'
C'module'
D'class'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'session' scope causes shared state across tests.
Using 'module' or 'class' scope may cause conflicts in parallel runs.
5fill in blank
hard

Fill all three blanks to define a pytest command line option to control parallel workers with a default of 2.

Selenium Python
def pytest_addoption(parser):
    parser.addoption(
        '--workers',
        action='store',
        default=[1],
        help='Number of parallel workers'
    )

def pytest_configure(config):
    workers = config.getoption('[2]')
    pytest.main(['-n', [3]])
Drag options to blanks, or click blank then click option'
A'2'
B'workers'
Cworkers
D'-n'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the option name instead of the variable to pytest.main.
Using integer instead of string for default.
Using wrong option name in getoption.