Other plugins

Envinfo

Envinfo plugin adds some details to test report header

args: python3 -m pytest -vv -x
hostname: machine-hostname
git: branch current_branch, commit_hash*, base base_commit_hash

In git: section

  • * indicates uncommitted changes

  • base_commit_hash points to a commit in develop branch from which the current branch diverges

To use envinfo plugin, add it to pytest_plugins in conftest.py

pytest_plugins = [
    # ...
    'testsuite.envinfo',
]

Retrieving git status can be slow in docker due to network-related issues. If it affects you, turn git status off by --envinfo-no-git flag.

Mocked_time

Fixtures

testsuite.plugins.mocked_time.mocked_time()[source]
Returns:

MockedTime

mocked_time fixture provides control over mock time in a centralized way.

Disabling mocked_time

  • mocked-time-enabled = false flag in pytest.ini disables mocked time by default.

  • --service-runner-mode command line flag disables mocked time by default.

When mocked time is disabled by default, it has to explicitly enabled to be used in a particular test: @pytest.mark.now('2016-12-01T12:00:00') or @pytest.mark.now(enabled=True).

If time is not specified in @pytest.mark.now, then current time at UTC timezone is used at the start of test as time value until it is modified by calling mocked_time.set(...) or mocked_time.sleep(...)

Timezones

Mocked time is always stored as offset-naive datetime in UTC timezone. mocked_time.set(...) treats offset-naive datetime as datetime in UTC timezone and converts offset-aware datetime to offset-naive automatically.

mocked_time.now() returns returns offset-naive datetime by default, but with tz arg it will return offset-aware datetime in tz timezone.

Classes

class testsuite.plugins.mocked_time.MockedTime(time: datetime, *, is_enabled: bool)[source]
now(tz: Optional[tzinfo] = None) datetime[source]
Returns:

current value of mock time

set(time: datetime)[source]

Set mock time value

sleep(delta: float) None[source]

Increase mock time value

Parameters:

delta – increase value in seconds