pytest¶
In order to provide some convenience a pytest.fixtures
has
been created.
Mailpit-API fixture¶
mailpit_api()
is a pytest
fixture
, that sets up an API connection and returns it as API
object.
The fixture has got a scope of session
and it will call API.delete_messages()
with an empty list to delete all messages, when it goes out of scope.
As with other pytest plugins you have to enable this library in your conftest.py
:
pytest_plugins = ["mailpit.testing.pytest"]
Now it is possible to use the fixture:
def test_example(mailpit_api):
mailpit_api.get_messages([])
The fixture has got a default of http://localhost:8025
.
In order to pass the api url to this fixture, you have to parametrize your test function with the indirect
parameter set to True
.
import pytest
api_url = "localhost:8025"
@pytest.mark.parametrize("mailpit_api", [api_url], indirect=True)
def test_example(mailpit_api):
mailpit_api.get_messages([])