Ever wonder why some projects seem able to make huge changes and still ship promptly, while others collapse under the weight of their own code? Testing is the difference! Effective tests enable you to add features quickly, refactor your code without fear, and ship new releases without big new bugs.
Make Your Project Successful by Writing Meaningful Tests
Python Testing with Green
Tests are just a way of writing code that uses your project and makes sure that it really does what you think it does! We'll learn the best way to write tests and some common problems and pitfalls that you should avoid.
This course is designed as a practical reference for Python programmers who have real code that they would like to start testing, or test more effectively. I provide real runnable examples that you can type in yourself or download from the resources section.
The beginner section requires zero prior testing knowledge. I teach the fundamental basics of testing Python code including how to run your tests the "traditional" way as well as with the high-performance Green test runner. After completing this section, you will be able to write tests and run them.
The intermediate section teaches you how to write meaningful tests, and covers every aspect of the Python "unittest" module that you will use in daily life. Upon completing this section, you will know more than most Python programmers about how to test your code.
In the advanced section I go over how to mock unit tests, integration testing, advanced usage of the Green test runner, and some tips and tricks for getting the most out of your testing. Only an elite few gain this level of knowledge on their own. After completing this section, you will be a master of Python testing.
Regarding Errors & Failures
Please see the "Skipping Tests" lecture in the Intermediate section for more in-depth information on skipping tests.
Quick review of ALL the concepts in the beginner section.
Did you learn the fundamentals?
How to specify specific and/or multiple test targets using Green.
How to get code coverage reports using Green.
How using your test as a design tool makes your test meaningful.
How writing a readable test makes your test meaningful.
How testing for one outcome makes your test meaningful.
How testing boundaries makes your test meaningful.
How testing the results of your code makes your test meaningful.
How isolating the unit you are testing makes your test meaningful.
How identifying the reason for your test makes your test meaningful.
Suggested ways to organize your unit test files, classes, and methods.
How (and when) to use test fixtures, class fixtures, and module fixtures.
A more in-depth look at ways to skip tests than the lecture in the beginner section:
In this section:
Overview of mock module:
The MagicMock object is vital to testing, unit testing especially. In part 1 we begin our journey covering all the most commonly-used parts of the versatile MagicMock object.
PART TWO!!! We bring it all in and learn all the rest that we need to know about the MagicMock...and a few other mock tidbits.
Learn how to patch your code to automatically replace real object with mocks and isolate the units you are testing.
Learn to use Green's powerful output options to customize your test reports.
How to initialize & finalize external resources (like databases) so that each worker process can have its own dedicated external resource and simultaneous tests don't interfere with each other.
Green uses multiple processes to run your tests in parallel by default. Learn exactly how that works, and what you can do to customize it. Run your tests FAST!
Green supports multiple config files to customize Green's behavior for your projects.
Green provides tab-completion of test targets for both bash and zsh! Setup is quick and easy.
Sometimes you want a test run to stop after the first failure.
Learn the correct way to create and clean up temporary files & directories, plus tips & information about how Green's worker processes use temporary directories and how you can identify worker processes.
Professional software developer since 2001. Founder of Agile Perception. C++, Python, Rust, Unreal Engine 4. I have been a graphic designer, webmaster, full stack developer, database admin, systems admin, system integrator, product manager, department manager, entrepreneur, and I still have to take out the garbage (both literally and metaphorically).