python pytest in python

To use pytest in Python, follow these steps:

  1. Install pytest by running the command pip install pytest in your command prompt or terminal.
  2. Create a new Python file and write test functions using the pytest framework. Here's an example of a test function:
main.py
def test_addition():
    assert 2+2 == 4
    assert 2+3 == 5
    assert 1+1 == 2
81 chars
5 lines
  1. Save your test file with a name starting with test_ (e.g. test_example.py).
  2. Run your test file using the command pytest in your command prompt or terminal.
  3. pytest will automatically discover and run all test functions starting with test_ and display the results.

You can also use pytest fixtures, plugins, and command-line options to customize your testing environment and behavior. For more information on pytest, refer to the official documentation: https://docs.pytest.org/en/latest/

gistlibby LogSnag