What did I learn from going through 2 hours of videos on Pytest ?

Python Testing 101

  • pytest the most popular Python package for testing
  • it is also a basis for rich ecosystem for testing plugins
  • unittesting comes with Python. It is used to test the internals of core python. It is a good solid tool but there are a lot of api calls that one might have to learn
  • The test should be divided in to three stages
    • Arrange : Setting up test, variables, data structure
    • Act : Execute the code on the above setting
    • Assert : Assert the way the code has run the test
  • If you are building a user interface, you build a CLI tool and then keep adding additional tests in pytest scripts

Python Testing 202

  • .’s are used to represent the number of functions tested in a test file
  • tests can expect an Exception and pytest can be used to check whether the right exceptions are occurring in the code.
  • What if you want to test more examples ?
  • The first assertion that fails aborts the rest of assertions
  • One can test a bunch of examples with parametrized feature
  • method is a function attached to a class
  • One can group the functionality in to a class
  • Pytest incorporates fixtures that helps you incorporate the set up that goes along with testing a function
  • fixtures should be a part of conftest.py
  • pytest has a built-in fixtures
  • pytest has a rich set of ecosystem that gives a set of variety of new fixtures
  • fixtures for setup/reuse
  • one can organize the test code in to classes

Takeaway

After working through the examples, I am now much more comfortable in going through the book on pytest. There is no doubt that I will be using all these things in the UOB project implementation