# Testing

Testing (which includes unit testing, integration testing, and regression testing) is very important for quality code; extremely so if the code is a library that will be used in other software.

## Test Framework: `pytest`

`aiosmtpd` uses the `pytest` testing framework. Advanced features of pytest are widely used throughout.

### Plugins

The one required plugin is `pytest-mock`; it is used extensively throughout the test suite.

Other plugins that are used, to various degrees, in the `aiosmtpd` test suite are:

- `pytest-cov` to integrate with `coverage-py`

- `pytest-sugar` to provide better ux

- `pytest-print` to give some progress indicator and to assist test troubleshooting

- `pytest-profiling` to implement `*-profile` testenv, although to be honest this is not really useful as the profiling gets ‘muddied’ by pytest runner.

### Fixtures

Below is a list of fixtures defined throught the test suite, in alphabetical order:

Important

As long as you create your test module(s) inside the `aiosmtpd/tests` directory, you do not need to import the above fixtures; they will automatically be available for use as they are defined in the `conftest.py` file.

Note

Individual test modules may define their own module-specific fixtures; please refer to their respective docstrings for description / usage guide.

### Markers

@client_data(...)

  Provides parameters to the :fixture:`~aiosmtpd.tests.conftest.client` fixture.

  Parameters

    connect_to (`HostPort`) – Address to connect to. Defaults to `Global.SrvAddr`

@controller_data(...)

  Provides parameters to the :fixture:`~aiosmtpd.tests.conftest.get_controller` fixture.

  Parameters

    - class_ – The class to be instantiated by `get_controller`. Will be overridden if `get_controller` is invoked with the `class_` argument.

    - host_port (str) – The “host:port” to bound to

    - **kwargs – Keyworded arguments given to the marker.

@handler_data(...)

  Provides parameters to the :fixture:`~aiosmtpd.tests.conftest.get_handler` fixture.

  Parameters

    - args_ – A tuple containing values that will be passed as positional arguments to the controller constructor

    - class_ – The class to be instantiated by `get_controller`

    - *args – Positional arguments given to the marker. Will override the `args_` keyword argument

    - **kwargs – Keyworded arguments given to the marker.