0
0
PyTesttesting~20 mins

Running PyTest in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PyTest Jenkins Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
PyTest command output in Jenkins pipeline
You run the following PyTest command in a Jenkins pipeline step:

pytest tests/ --junitxml=results.xml

What will be the main effect of this command?
PyTest
pytest tests/ --junitxml=results.xml
APyTest runs tests but fails because '--junitxml' is not a valid option.
BPyTest runs tests and outputs results only to the console, ignoring the XML file.
CPyTest runs tests in the 'tests/' folder and saves test results in XML format to 'results.xml'.
DPyTest runs tests and saves results in JSON format to 'results.xml'.
Attempts:
2 left
💡 Hint
Look for the meaning of the '--junitxml' option in PyTest.
Configuration
intermediate
2:00remaining
Jenkinsfile step to run PyTest and archive results
Which Jenkinsfile snippet correctly runs PyTest tests and archives the JUnit XML test report for Jenkins to display?
A
steps {
  sh 'pytest tests/ --junitxml=results.xml'
  junit 'results.xml'
}
B
steps {
  sh 'pytest tests/'
  archiveArtifacts 'results.xml'
}
C
steps {
  sh 'pytest tests/ --junitxml=results.xml'
  archiveArtifacts 'results.xml'
}
D
steps {
  sh 'pytest tests/ --xml=results.xml'
  junit 'results.xml'
}
Attempts:
2 left
💡 Hint
Jenkins uses the 'junit' step to process JUnit XML reports.
Troubleshoot
advanced
2:00remaining
PyTest test results not showing in Jenkins
You configured Jenkins to run PyTest with '--junitxml=results.xml' and added 'junit "results.xml"' in the pipeline. However, Jenkins shows no test results after the build. What is the most likely cause?
AThe 'junit' step must be called before running PyTest.
BThe 'results.xml' file was not created because PyTest failed before tests ran.
CJenkins cannot read XML files generated by PyTest.
DThe 'junit' step requires the XML file to be named 'test-results.xml'.
Attempts:
2 left
💡 Hint
Check if the XML file exists after the build.
🔀 Workflow
advanced
2:00remaining
Best Jenkins pipeline stage order for PyTest and coverage
You want to run PyTest with coverage reporting in Jenkins and publish both test results and coverage reports. Which pipeline stage order is correct?
APublish coverage report, run PyTest with coverage, then publish test results.
BRun PyTest with coverage, publish coverage report, then publish test results.
CPublish test results, run PyTest with coverage, then publish coverage report.
DRun PyTest with coverage, publish test results, then publish coverage report.
Attempts:
2 left
💡 Hint
Test results must be published after tests run.
🧠 Conceptual
expert
2:00remaining
Why use '--junitxml' option with PyTest in Jenkins?
What is the main reason to use the '--junitxml' option when running PyTest in a Jenkins pipeline?
ATo generate an XML file that Jenkins can parse to display detailed test results and trends.
BTo speed up test execution by running tests in parallel.
CTo automatically fix failing tests during the build.
DTo convert test results into JSON format for Jenkins.
Attempts:
2 left
💡 Hint
Think about how Jenkins shows test reports.