February 2022
Intermediate to advanced
274 pages
6h 28m
English
Mocking is a powerful tool for testing, and it’s important to know how to use it. Spending a bit of time now to play with mocks will help solidify the concepts and help you recognize places in your testing future where you may want to use mocks.
For the exercise, we’ll use a small script called my_info.py:
| | from pathlib import Path |
| | |
| | |
| | def home_dir(): |
| | return str(Path.home()) |
| | |
| | |
| | if __name__ == "__main__": |
| | print(home_dir()) |
The home_dir() function utilizes pathlib to get a users home directory. Just to show you how it works, the __name__ == "__main__" allows us to see it in action. This is what it looks like for me:
| | $ cd /path/to/code/exercises/ch10 |
| | $ python my_info.py ... |
Read now
Unlock full access