Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and, as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Foreword
pytest is one of the projects that show off the best qualities of Python; it is the easiest Python testing framework to get started and also the most powerful. The pytest developers leverage metaprogramming to help users; we can write tests as plain functions and use the
assert keyword for checks, which means we can use any Python expression as a check, and we don't need to memorize the names of dozens of assertThis, assertThat methods. When there is a test failure, pytest uses sophisticated introspection to show the difference between the expected value and the value returned by the code under test. Introspection and decorators are also used to provide fixtures, parameters, grouping, skipping, and such like.
pytest is basically two parts: a library that gives you the API to write tests, and a test runner, a command-line utility that can search and execute tests across your project packages. The behavior of the pytest CLI can be configured in many ways, as described in this guide. By default, pytest is smart enough to collect tests written with the standard unittest package as well as doctest, running them and reporting all their results together. This means you can start using pytest now to run the tests you've already written with unittest and doctest.
pytest is very powerful out of the box, but it can also be enhanced by a large collection of industrial-strength plugins. A good collection of the best plugins is covered in this book.
If you are in the business of writing libraries and APIs for others to use, pytest is not only a great tool, but also a plentiful source of ideas and techniques, leveraging the best features of Python.
Anyone willing to learn pytest will be lucky to be guided by Bruno Oliveira, a long-time core developer of this most practical, powerful, and Pythonic package.
Thank you for your work on pytest, Bruno and for writing this book.
Valeu!
Luciano Ramalho
Principal consultant at Thoughtworks and author of Fluent Python
Contributors
About the author
Bruno Oliveira is a software developer with 18 years experience working at ESSS, developing desktop and web applications for simulation and numerical analysis for several industry sectors including oil and gas, aerospace, automotive, and chemical processes. Having taken part in the development of an internal testing framework to attend to the various needs of the applications he worked with, and having always been interested in testing and software quality, in 2012, Bruno took note of pytest and immediately fell in love with the project. He started contributing whenever he could and has been a pytest core contributor since 2014.
About the reviewers
Igor T. Ghisi is a software developer with a BSc in computer science and an MSc in computational mechanics. He has worked for 10 years in the largest research center in Latin America, in Rio de Janeiro, building software for R&D in engineering using agile practices, with a focus on the oil and gas industry. He developed software for 3D Mesh Generation, Mesh Visualization, Reservoir Simulation, Uncertainty, and Multi-disciplinary Optimization . He switched to web development over the last four years to solve engineering problems using web and cloud technologies.
Edson Tadeu Monteiro Manoel has more than 15 years' experience working in scientific software development, mostly using a mix of C++ and Python. He has been using pytest in his everyday work since 2013.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.