0
0
PyTesttesting~5 mins

First PyTest test - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is PyTest used for?
PyTest is a tool to write and run tests for Python code. It helps check if your code works as expected.
Click to reveal answer
beginner
How do you name a test function in PyTest?
Test functions should start with the word test_. For example, def test_addition():.
Click to reveal answer
beginner
What does an assertion do in a PyTest test?
An assertion checks if a condition is true. If it is false, the test fails and shows an error.
Click to reveal answer
beginner
How do you run tests using PyTest?
You run tests by typing pytest in the command line inside your project folder.
Click to reveal answer
beginner
What is the output when a PyTest test passes?
PyTest shows a dot . for each passing test and a summary saying how many tests passed.
Click to reveal answer
Which prefix should a PyTest test function have?
Atest_
Bcheck_
Crun_
Dassert_
What happens if an assertion in a PyTest test fails?
APyTest skips the test
BThe test passes anyway
CThe test fails and shows an error
DPyTest crashes
How do you run all tests in a folder using PyTest?
ARun <code>run_tests()</code> in Python
BRun <code>python test.py</code>
COpen tests in an editor
DRun <code>pytest</code> in the command line
What symbol does PyTest show for a passing test?
AF
B.
CE
DS
Which of these is a valid simple PyTest test function?
Adef test_sum(): assert 1 + 1 == 2
Bdef check_sum(): assert 1 + 1 == 2
Cdef sum_test(): assert 1 + 1 == 2
Ddef sum(): assert 1 + 1 == 2
Explain how to write and run your first test using PyTest.
Think about the steps from writing code to seeing the test result.
You got /4 concepts.
    Describe what happens when a PyTest test passes and when it fails.
    Focus on the test output symbols and messages.
    You got /3 concepts.