Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to publish test results using pytest's command line option.
PyTest
pytest.main(['--[1]=result.xml'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--html' instead of '--junitxml' to generate XML results.
Forgetting to specify the output file name.
✗ Incorrect
The '--junitxml' option tells pytest to save test results in an XML file named 'result.xml'.
2fill in blank
mediumComplete the code to import the pytest module needed for publishing test results.
PyTest
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'unittest' instead of 'pytest'.
Importing unrelated modules like 'mock'.
✗ Incorrect
The 'pytest' module is required to run tests and publish results using pytest commands.
3fill in blank
hardFix the error in the code to correctly publish test results to an XML file.
PyTest
pytest.main(['--junitxml=[1]'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a text or HTML file extension instead of XML.
Using a file name without an extension.
✗ Incorrect
The file name must have an '.xml' extension to be a valid JUnit XML report.
4fill in blank
hardFill both blanks to create a pytest command that runs tests and publishes results in XML format.
PyTest
pytest.main(['[1]', '--[2]=test_results.xml'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-q' which is quiet mode instead of verbose.
Using '--html' instead of '--junitxml' for XML output.
✗ Incorrect
The '-v' option runs tests in verbose mode, and '--junitxml' publishes results to 'test_results.xml'.
5fill in blank
hardFill all three blanks to define a pytest test function and publish results to 'output.xml'.
PyTest
import pytest def test_[1](): assert [2] == [3] pytest.main(['--junitxml=output.xml'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the test function without 'test_' prefix.
Using incorrect assertion values that fail the test.
✗ Incorrect
The test function is named 'test_addition', asserting that 2 + 2 equals 4, and results are published to 'output.xml'.