Python Testing with Green
5.0 (4 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
43 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Python Testing with Green to your Wishlist.

Add to Wishlist

Python Testing with Green

Concepts, best practices, explanations & instructions on how to effectively test your Python code.
5.0 (4 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
43 students enrolled
Created by Nathan Stocks
Last updated 5/2017
English
Current price: $10 Original price: $200 Discount: 95% off
1 day left at this price!
30-Day Money-Back Guarantee
Includes:
  • 3.5 hours on-demand video
  • 31 Supplemental Resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Improve code quality.
  • Refactor code without fear.
  • Have a better coding experience.
  • Be able to better help others.
View Curriculum
Requirements
  • Familiarity with Python
Description

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

  • Layout your test packages and modules correctly
  • Organize your tests effectively
  • Learn the tools in the unittest module
  • Run your test with Green, a powerful new test runner
  • Write meaningful tests that enable quick refactoring
  • Learn the difference between unit and integration tests
  • Use advanced tips and tricks to get the most out of your 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.

Who is the target audience?
  • Likes pretty colors
  • Believes that testing can improve their code
  • Prefers interfaces carefully crafted for usability AND aesthetics
  • Believes fast tests are better than slow tests
  • Understands that a good continuous integration solution improves quality of life.
Students Who Viewed This Course Also Viewed
Curriculum For This Course
Expand All 46 Lectures Collapse All 46 Lectures 03:25:33
+
Introduction
2 Lectures 04:01

Course introduction

  • About the Instructor (Nathan Stocks)
  • Motivations behind creating this course
  • Benefits of this course
  • What You Will learn
  • Course Overview
  • Target Audience
Preview 01:56

  • Invitation to join our community on the PythonLearning Discord server.
  • Python documentation website
Community & Help
02:05
+
Beginner: Fundamental Python Testing Concepts
9 Lectures 44:58

How to run your first test in Python.

Preview 05:25

  • Test package (directory) naming & layout
  • Test module (file) naming & layout
Preview 07:52

  • Docstring - what it is and how to make one.
  • How docstrings are used in tests
Preview 03:02

unittest.TestCase methods:

  • self.assertTrue(expression)
  • self.assertFalse(expression)
Preview 01:52

unittest.TestCase methods:

  • self.fail(message)
fail()
04:04

Regarding Errors & Failures

  • Where an error comes from
  • How an error is presented in a test report
  • Where a failure comes from
  • How a failure is presented in a test report
  • The difference between failures and errors
Errors
01:53

Skipped Tests

  • What a skipped test looks like
  • Some ways to skip a test

Please see the "Skipping Tests" lecture in the Intermediate section for more in-depth information on skipping tests.

unittest.skip() decorator and skipTest()
06:47

Expected Failure

  • What it means to have an expected failure
  • How to mark a test as an expected failure
unittest.expectedFailure decorator
02:39

Quick review of ALL the concepts in the beginner section.

Fundamentals Review
11:24

Did you learn the fundamentals?

Fundamentals Quiz
10 questions
+
Intermediate: All The Things You Need to Know
23 Lectures 01:40:59
  • Target audience for this section.  If you are comfortable with the content in the Fundamentals Review, then you are ready for this section!
  • Overview of lecture format for this section.
Preview 01:17

How to specify specific and/or multiple test targets using Green.

Green: Target Specification
05:21

How to get code coverage reports using Green.

Green: Coverage
11:11

Quick introduction to what makes a meaningful test.

Preview 01:06

How using your test as a design tool makes your test meaningful.

Meaningful Tests: 1. Design Tool
03:33

How writing a readable test makes your test meaningful.

Meaningful Tests: 2. Readable Tests
04:50

How testing for one outcome makes your test meaningful.

Meaningful Tests: 3. Test One Outcome
04:42

How testing boundaries makes your test meaningful.

Meaningful Tests: 4. Test Boundaries
04:19

How testing the results of your code makes your test meaningful.

Meaningful Tests: 5. Test Results
04:09

How isolating the unit you are testing makes your test meaningful.

Meaningful Tests: 6. Isolate the Unit
01:37

How identifying the reason for your test makes your test meaningful.

Meaninfgul Tests: 7. Identify the Reason
05:51

Suggested ways to organize your unit test files, classes, and methods.

Unit Test Organization
04:13

How (and when) to use test fixtures, class fixtures, and module fixtures.

Fixtures
13:27

unittest.TestCase methods:

  • self.assertEqual(arg1, arg2, [message])
  • self.assertNotEqual(arg1, arg2, [message])
assertEqual, assertNotEqual
06:26

unittest.TestCase methods:

  • self.assertGreater(left, right, [message])
  • self.assertGreaterEqual(left, right, [message])
  • self.assertLess(left, right, [message])
  • self.assertLessEqual(left, right, [message])
assertGreater, assertGreaterEqual, assertLess, assertLessEqual
01:25

unittest.TestCase methods:

  • self.assertIs(arg1, arg2, [message])
  • self.assertIsNot(arg1, arg2, [message])
  • self.assertIsNone(arg1, [message])
  • self.assertIsNotNone(arg1, [message])
assertIs, assertIsNot, assertIsNone, assertIsNotNone
04:38

unittest.TestCase methods:

  • self.assertIn(item, collection, [message])
  • self.assertNotIn(item, collection, [message])
assertIn, assertNotIn
01:19

unittest.TestCase methods 

  • self.assertIsInstance(obj, class, [message])
  • self.assertNotIsInstance(obj, class, [message])
assertIsInstance, assertNotIsInstance
04:01

unittest.TestCase methods:

  • self.assertRaises(exception, callable, [arg1, arg2, ...], [kwarg1=x, kwarg2=y, ...])
  • self.assertRaisesRegexp(exception, pattern, callable, [arg1, arg2, ...], [kwarg1=x, kwarg2=y, ...])


assertRaises, assertRaisesRegexp
05:20

unittest.TestCase methods:

  • self.assertItemsEqual(collection1, collection2, [message])
assertItemsEqual (assertCountEqual in Python 3)
02:21

unittest.TestCase methods:

  • self.assertAlmostEqual(arg1, arg2, [places=7], [message], [delta])
  • self.assertNotAlmostEqual(arg1, arg2, [places=7], [message], [delta])
assertAlmostEqual, assertNotAlmostEqual
03:54

unittest.TestCase methods:

  • self.assertRegexpMatches(text, pattern, [message])
  • self.assertNotRegexpMatches(text, pattern, [message])
assertRegexpMatches, assertNotRegexpMatches
02:16

A more in-depth look at ways to skip tests than the lecture in the beginner section:

  • @unittest.skip(message)
  • @unittest.skipIf(condition, message)
  • @unittest.skipUnless(condition, message)
  • self.skipTest(message)
  • raise unittest.SkipTest(message)
Skipping Tests
03:43
+
Advanced: Power Tools
12 Lectures 55:35

In this section:

  • Mock objects for unit tests
  • Green's powerful features
  • Integration Testing & Continuous Integration
  • Tips & Tricks
Advanced Section Overview
00:27

Overview of mock module:

  • Portable imports
  • MagicMock: Introduction to calls, attributes, methods, return values, side effects, and patching.
Mock Overview
05:21

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.

Magic Mock - Part 1
08:19

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.

Magic Mock - Part 2
06:53

Learn how to patch your code to automatically replace real object with mocks and isolate the units you are testing.

Mock Patchers
09:35

Learn to use Green's powerful output options to customize your test reports.

Green - Output Options
06:10

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 - Initializer & Finalizer
04:51

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 - Number of Processes
04:10

Green supports multiple config files to customize Green's behavior for your projects.

Green - Config Files
03:03

Green provides tab-completion of test targets for both bash and zsh!  Setup is quick and easy.

Green - bash & zsh tab-completion
02:26

Sometimes you want a test run to stop after the first failure.

Green - Fail Fast
01:44

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.

Temporary Files & Directories
02:36
About the Instructor
Nathan Stocks
5.0 Average rating
4 Reviews
43 Students
1 Course
Software Developer at Agile Perception

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).