O'Reilly logo
live online training icon Live Online training

Testing in Python

Create, configure, and extend tests with Pytest

Noah Gift
Alfredo Deza

Testing, and unit-testing in particular, is one of the principal pillars for writing robust software. Although Python comes with a unit testing library, it is not easily extensible, it is hard to understand, and it doesn’t include an easy way to run and report on tests.

Learn the different types of testing like functional and load testing. Tools like Pytest, Coverage, Molotov, and Tox will be covered in enough detail to apply them to existing projects and get them to a solid production state.

And finally, learn how to integrate the different types of testing and tooling into continuous integration / continuous delivery platforms like Jenkins to ensure a smooth deployment (or release).

What you'll learn-and how you can apply it

  • Understand best practices to write and extend test suites using Pytest.
  • Extend Pytest with ad-hoc plugins, fixtures, and parametrization.
  • Enhance coverage, reporting, and improve robustness with readable tests.
  • Perform load testing.
  • Support different Python versions and other ad-hoc testing with Tox.
  • Produce solid deployments by configuring git services like Github or Gitlab to execute tests automatically when merging and before merging code.

This training course is for you because...

  • You work as a software engineer, and you are exposed to production code that could use new tests to be written or improve existing unit tests to get better validation.
  • You work as a data scientist and want to better understand how to validate and enhance robustness to production code.
  • You are a student with some exposure to Python and want to gain knowledge on the industry’s best standards for producing code that is well tested.

About your instructor

  • Noah Gift is lecturer and consultant at both UC Davis Graduate School of Management MSBA program and the Graduate Data Science program, MSDS, at Northwestern. He is teaching and designing graduate machine learning, AI, Data Science courses and consulting on Machine Learning and Cloud Architecture for students and faculty. These responsibilities including leading a multi-cloud certification initiative for students. He has published close to 100 technical publications including two books on subjects ranging from Cloud Machine Learning to DevOps. Gift received an MBA from UC Davis, a M.S. in Computer Information Systems from Cal State Los Angeles, and a B.S. in Nutritional Science from Cal Poly San Luis Obispo.

    Professionally, Noah has approximately 20 years’ experience programming in Python. He is a Python Software Foundation Fellow, AWS Subject Matter Expert (SME) on Machine Learning, AWS Certified Solutions Architect and AWS Academy Accredited Instructor, Google Certified Professional Cloud Architect, Microsoft MTA on Python. He has worked in roles ranging from CTO, General Manager, Consulting CTO and Cloud Architect. This experience has been with a wide variety of companies including ABC, Caltech, Sony Imageworks, Disney Feature Animation, Weta Digital, AT&T, Turner Studios and Linden Lab. In the last ten years, he has been responsible for shipping many new products at multiple companies that generated millions of dollars of revenue and had global scale. Currently he is consulting startups and other companies.

  • Alfredo Deza is a former professional athlete and Olympian, with 10 years of professional Python and DevOps experience, creating large CI/CD environments for testing and deployments, has designed resilient infrastructure for several companies, and has instilled his passion for testing to others by automating code checks and production deployments. Often presenting at technology conferences, like PyCon, and most recently LatinoWare in Brazil, and upcoming Cephalocon in Spain. He is currently writing a book on DevOps for O’reilly.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Part 1: Introduction to Pytest (45 min) - Create a Git repository for testing - Get started with pytest

Q&A (10 min)

Break (5 min)

Part 2: Further Pytest usage (45 min)

  • Debug pytest
  • Using pytest fixtures

Q&A (10 min)

Break (5 min)

Part 3: Advanced testing and automation (45 min) - Monkeypatching with pytest - Temporary directories - Exploring built-in fixtures with pytest - Install and use pytest plugins - Use Tox - Loadtest Python code

Q&A (10 min)

Break (5 min)

Part 4: Case Studies (45 min)

  • Understand Test system architecture
  • Continuous integration and Python testing
  • What is unitesting, functional testing, and load testing?

Q&A (15 min)