-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytest_notimplemented.py
88 lines (62 loc) · 2.2 KB
/
pytest_notimplemented.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright © 2019 Damien Flament
# This file is part of pytest-notimplemented.
"""A pytest plugin providing a marker for not implemented features and tests.
@mark.notimplemented
--------------------
The `notimplemented` marker is designed to be used for tests which should fail because
the feature is not yet implemented.
As tests on not implemented features should fail, it is just syntatic sugar for a
standard `xfail` marker with a "Not implemented" message.
```python
from pytest import mark
@mark.notimplemented
def test_foo(foo):
assert foo.baz()
@mark.xfail("Not implemented")
def test_bar(bar):
assert bar.baz()
```
@mark.notwritten
-----------------
The `notwritten` marker is is designed to be used for tests which are declared but not
defined. Those kind of tests are just placeholders to help the developer remember that
the behavior must be tested. And that marker helps on it.
As not written tests (or tests not finished to write) are impredictable, they must be
skipped. That marker is just syntatic sugar for a standard `skip` marker with a
"Not written" message.
```python
from pytest import mark
@mark.notwritten
def test_foo(foo):
pass
@mark.skip("Not written")
def test_bar(bar):
pass
```
"""
from pytest import hookimpl, mark
@hookimpl
def pytest_configure(config):
"""Registers additonal markers.
Markers provided by this plugin are registered:
- `notimplemented`
- `notwritten`
"""
config.addinivalue_line(
"markers", "notimplemented: mark a test as related to a non implemented feature"
)
config.addinivalue_line("markers", "notwritten: mark a test as not written")
@hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
"""Apply custom markers.
Marks:
- not implemented tests as expected to fail,
- not written tests as skipped.
"""
not_implemented = item.get_closest_marker("notimplemented")
not_written = item.get_closest_marker("notwritten")
if not_implemented:
item.add_marker(mark.xfail(reason="Not implemented"))
if not_written:
item.add_marker(mark.skip(reason="Not written"))