0
0
PyTesttesting~5 mins

Grouping related tests in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of grouping related tests in pytest?
Grouping related tests helps organize tests logically, making them easier to read, maintain, and run selectively.
Click to reveal answer
beginner
How can you group related tests in pytest using functions?
You can group related tests by placing them in the same Python file or by using classes without __init__ methods to logically group test functions.
Click to reveal answer
intermediate
What is a pytest test class and how does it help in grouping tests?
A pytest test class is a class whose name starts with 'Test'. It groups related test functions inside it, helping organize tests and share setup code.
Click to reveal answer
intermediate
How do pytest markers help in grouping tests?
Markers label tests with custom tags. You can run tests with specific markers to group and execute related tests selectively.
Click to reveal answer
beginner
Give an example of grouping tests using a pytest class.
Example:
class TestMathOperations:
    def test_add(self):
        assert 1 + 1 == 2
    def test_subtract(self):
        assert 2 - 1 == 1
This groups add and subtract tests logically.
Click to reveal answer
Which of the following is a valid way to group related tests in pytest?
AUsing test classes with names starting with 'Test'
BWriting all tests in one long function
CUsing global variables to separate tests
DRunning tests in random order
What is the benefit of using pytest markers for grouping tests?
AThey disable tests permanently
BThey speed up test execution automatically
CThey convert tests into functions
DThey allow running only selected groups of tests
How do you name a pytest test class to ensure pytest recognizes it?
AStart the class name with 'Test'
BEnd the class name with 'Test'
CInclude 'test' anywhere in the class name
DUse uppercase letters only
Which statement about grouping tests in pytest is TRUE?
AGrouping tests slows down test execution
BGrouping tests helps maintain and run tests more easily
CGrouping tests is not supported in pytest
DGrouping tests requires special plugins only
What is the recommended way to share setup code among grouped tests in pytest?
AUse global variables outside tests
BCopy-paste setup code in every test
CUse setup methods inside test classes or fixtures
DRun tests in a specific order
Explain how you can group related tests in pytest and why it is useful.
Think about classes, markers, and file organization.
You got /4 concepts.
    Describe how pytest markers work for grouping tests and how to run tests with a specific marker.
    Focus on marking and running tests selectively.
    You got /4 concepts.