pytest¶
pytest --tb=short --show-capture=no --disable-warnings -x
freezegun¶
To use freezegun
as a context manager,
pip uninstall pytest-freezegun
pip install freezegun
from freezegun import freeze_time
with freeze_time("2017-05-21"):
UserConsent.objects.set_consent(consent, True, user_1)
UserConsent.objects.set_consent(consent, False, user_2)
Or use a date/time:
import pytz
from datetime import datetime
with freeze_time(datetime(2017, 5, 21, 21, 30, 0)):
pytest-freezegun¶
Warning
I had some issues with pytest-freezegun
, but I think the
problem was that I had not included it in requirements/ci.txt
.
I prefer to use the context manager with freezegun
, so the
following notes are just for information…
https://github.com/ktosiek/pytest-freezegun
@pytest.mark.freeze_time("2017-05-21")
def test_report():
Markers¶
To register a marker e.g:
@pytest.mark.elasticsearch
Create a conftest.py
file
e.g. dash/tests/conftest.py
or example_crm/tests/conftest.py
and add the following:
# -*- encoding: utf-8 -*-
def pytest_configure(config):
config.addinivalue_line(
"markers", "elasticsearch: enable or disable tests using elasticsearch"
)
For more information, see Registering marks.
Tip
This doesn’t seem to work using setup.cfg
or pytest.ini
(I had problems with configurations being ignored).
Warnings¶
-p no:warnings
# e.g.
pytest --color=yes --tb=short --show-capture=no --html=report.html --fail-on-template-vars -p no:warnings
or:
[pytest]
addopts = -p no:warnings