-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_debug_logging.py
44 lines (39 loc) · 986 Bytes
/
test_debug_logging.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
import pytest
import debug
import os
#
# Debug
#
@pytest.mark.usefixtures("tmpdir", "monkeypatch")
@pytest.hookimpl(tryfirst=True)
@pytest.mark.debug
def test_log(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
debug.debug("This is a test log")
with open(os.path.join(".", "debug.log")) as f:
txt = f.read()
assert txt=="\"\"\" This is a test log \"\"\"\n"
#
# conftest.py
#
class It():
def __init__(self) -> None:
self.data = "Data"
def clear(self) -> None:
del self.data
@pytest.hookimpl(tryfirst=True)
@pytest.mark.debug
def test_conftest_success():
import conftest
conftest.Fail = False
item = It()
conftest.pytest_collection_modifyitems(None, item)
assert hasattr(item, "data")
@pytest.hookimpl(tryfirst=True)
@pytest.mark.debug
def test_conftest_fail():
import conftest
conftest.Fail = True
item = It()
conftest.pytest_collection_modifyitems(None, item)
assert not hasattr(item, "data")