Recall & Review
beginner
What is subprocess testing in software testing?
Subprocess testing checks how a program runs other programs or commands outside itself. It ensures these external calls work correctly.
Click to reveal answer
beginner
Which Python module is commonly used to run subprocesses in tests?
The
subprocess module lets Python code start and control other programs. It is often used in subprocess testing.Click to reveal answer
intermediate
How can you check the output of a subprocess in pytest?
Use
subprocess.run() with capture_output=True to get the output. Then assert the output matches expected results.Click to reveal answer
intermediate
Why should subprocess calls be mocked in unit tests?
Mocking subprocess calls avoids running real commands, which can be slow or unsafe. It helps tests run fast and reliably.
Click to reveal answer
advanced
What is a good practice for locating subprocess commands in tests?
Use absolute paths or environment variables to locate commands. This avoids errors from missing or wrong commands during tests.
Click to reveal answer
Which function runs a subprocess and waits for it to finish in Python?
✗ Incorrect
subprocess.run() runs a command and waits for it to complete, returning a result object.
In pytest, how do you capture the output of a subprocess?
✗ Incorrect
Setting capture_output=True captures stdout and stderr for assertions.
Why mock subprocess calls in unit tests?
✗ Incorrect
Mocking prevents side effects and speeds up tests.
What does
subprocess.CompletedProcess contain?✗ Incorrect
This object holds the result details after subprocess finishes.
Which is a best practice for subprocess command paths in tests?
✗ Incorrect
Absolute paths avoid errors from missing or wrong commands.
Explain how to test a subprocess call using pytest, including capturing output and making assertions.
Think about how to run the command and check what it prints or returns.
You got /4 concepts.
Describe why and how you would mock subprocess calls in unit tests.
Consider the risks of running real commands during tests.
You got /4 concepts.