conftest module¶
-
class
conftest.
SingleSet
[source]¶ Bases:
set
Set only allowing values to be added once
When addition of a duplicate value is detected, the DuplicateKeyError exception will be raised, all non duplicate values are added to the set.
- Raises
DuplicateKeyError - when adding a value already in the set –
>>> ss = SingleSet({1, 2, 3, 4}) >>> ss.add(3) Traceback (most recent call last): ... conftest.DuplicateKeyError: Value 3 already present >>> ss.update({4, 5, 6, 3}) Traceback (most recent call last): ... conftest.DuplicateKeyError: Value(s) {3, 4} already present >>> ss SingleSet({1, 2, 3, 4, 5, 6}) >>>
NB: - duplicate values on initialization are not detected >>> ss = SingleSet({1, 2, 3, 4, 3, 2, 1}) >>> ss SingleSet({1, 2, 3, 4})
-
conftest.
serialize_datetimes
(obj)[source]¶ Serializes datetimes to ISO format strings.
Used on report test_metadata since pytest-json doesn’t let us pass options to the serializer.
>>> from datetime import datetime >>> serialize_datetimes({datetime(2000, 1, 1): -1}) {'2000-01-01T00:00:00': -1} >>> serialize_datetimes({'foo': datetime(2000, 1, 1)}) {'foo': '2000-01-01T00:00:00'}