Say you have a function that converts text and you’d like to it. You can write a directory with input and output and use pytest.parameterize to iterate over the . The problem is that the input and the output are in different files and it’s not obvious to see them next to each other.

If the text for testing is not that long, you can place all the cases in a configuration file. In this example I’ll be using TOML format to hold the cases and each case will be in a table in array of tables. You can probably do the same with multi document YAML.

Here’s the are the test cases
And here’s the testing code (mask removes passwords from the text)
When running , you’ll see the following:

$ python -m pytest -v
========================================= test session starts =========================================
platform linux — Python 3.7.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0 — /home/miki/.local/share/virtualenvs/pytest-cmp-F3l45TQF/bin/python
cachedir: .pytest_cache
rootdir: /home/miki/Projects/pythonwise/pytest-cmp, inifile:
collected 3 items                                                                              [passwd] PASSED                                                          [ 33%][password] PASSED                                                        [ 66%][no change] PASSED                                                       [100%]

====================================== 3 passed in 0.01 seconds =======================================

Source link


Please enter your comment!
Please enter your name here