Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 219764f

Browse files
conftest.py is updated [refactoring]
- Unification for pytest and unittest cases: - pytest.Function - _pytest.unittest.TestCaseFunction - Achthung tests [with problems in fixtures?] - Cleanup
1 parent 76fa94c commit 219764f

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

tests/conftest.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# /////////////////////////////////////////////////////////////////////////////
22
# PyTest Configuration
33

4-
import _pytest.outcomes
5-
64
import pluggy
75
import pytest
8-
import _pytest
96
import os
107
import logging
118
import pathlib
129
import math
1310
import datetime
1411

12+
import _pytest.outcomes
13+
import _pytest.unittest
14+
import _pytest.logging
15+
1516
# /////////////////////////////////////////////////////////////////////////////
1617

1718
C_ROOT_DIR__RELATIVE = ".."
@@ -91,10 +92,6 @@ def GetCurrentTestWorkerSignature() -> str:
9192
return __class__.sm_CurrentTestWorkerSignature
9293

9394

94-
# /////////////////////////////////////////////////////////////////////////////# /////////////////////////////////////////////////////////////////////////////
95-
# Fixtures
96-
97-
9895
# /////////////////////////////////////////////////////////////////////////////
9996
# TEST_PROCESS_STATS
10097

@@ -198,10 +195,13 @@ def helper__makereport__setup(
198195
assert item is not None
199196
assert call is not None
200197
assert outcome is not None
201-
assert type(item) == pytest.Function # noqa: E721
198+
# it may be pytest.Function or _pytest.unittest.TestCaseFunction
199+
assert isinstance(item, pytest.Function)
202200
assert type(call) == pytest.CallInfo # noqa: E721
203201
assert type(outcome) == pluggy.Result # noqa: E721
204202

203+
C_LINE1 = "******************************************************"
204+
205205
# logging.info("pytest_runtest_makereport - setup")
206206

207207
TEST_PROCESS_STATS.incrementTotalTestCount()
@@ -214,26 +214,32 @@ def helper__makereport__setup(
214214
TEST_PROCESS_STATS.incrementNotExecutedTestCount()
215215
return
216216

217-
assert rep.outcome == "passed"
218-
219-
testNumber = TEST_PROCESS_STATS.incrementExecutedTestCount()
220-
221217
testID = ""
222218

223219
if item.cls is not None:
224220
testID = item.cls.__module__ + "." + item.cls.__name__ + "::"
225221

226222
testID = testID + item.name
227223

228-
if testNumber > 1:
229-
logging.info("")
224+
if rep.outcome == "passed":
225+
testNumber = TEST_PROCESS_STATS.incrementExecutedTestCount()
230226

231-
logging.info("******************************************************")
232-
logging.info("* START TEST {0}".format(testID))
227+
logging.info(C_LINE1)
228+
logging.info("* START TEST {0}".format(testID))
229+
logging.info("*")
230+
logging.info("* Path : {0}".format(item.path))
231+
logging.info("* Number: {0}".format(testNumber))
232+
logging.info("*")
233+
return
234+
235+
assert rep.outcome != "passed"
236+
237+
logging.info(C_LINE1)
238+
logging.info("* ACHTUNG TEST {0}".format(testID))
233239
logging.info("*")
234-
logging.info("* Path : {0}".format(item.path))
235-
logging.info("* Number: {0}".format(testNumber))
240+
logging.info("* Outcome is [{0}]".format(rep.outcome))
236241
logging.info("*")
242+
return
237243

238244

239245
# ------------------------------------------------------------------------
@@ -243,12 +249,11 @@ def helper__makereport__call(
243249
assert item is not None
244250
assert call is not None
245251
assert outcome is not None
246-
assert type(item) == pytest.Function # noqa: E721
252+
# it may be pytest.Function or _pytest.unittest.TestCaseFunction
253+
assert isinstance(item, pytest.Function)
247254
assert type(call) == pytest.CallInfo # noqa: E721
248255
assert type(outcome) == pluggy.Result # noqa: E721
249256

250-
# logging.info("pytest_runtest_makereport - call")
251-
252257
rep = outcome.get_result()
253258
assert rep is not None
254259
assert type(rep) == pytest.TestReport # noqa: E721
@@ -350,6 +355,7 @@ def helper__makereport__call(
350355
logging.info("* EXIT STATUS : {0}".format(exitStatus))
351356
logging.info("*")
352357
logging.info("* STOP TEST {0}".format(testID))
358+
logging.info("*")
353359

354360

355361
# /////////////////////////////////////////////////////////////////////////////
@@ -359,17 +365,14 @@ def helper__makereport__call(
359365
def pytest_runtest_makereport(item: pytest.Function, call: pytest.CallInfo):
360366
assert item is not None
361367
assert call is not None
362-
assert type(item) == pytest.Function # noqa: E721
368+
# it may be pytest.Function or _pytest.unittest.TestCaseFunction
369+
assert isinstance(item, pytest.Function)
363370
assert type(call) == pytest.CallInfo # noqa: E721
364371

365-
# logging.info("[pytest_runtest_makereport][#001][{0}][{1}]".format(item.name, call.when))
366-
367372
outcome: pluggy.Result = yield
368373
assert outcome is not None
369374
assert type(outcome) == pluggy.Result # noqa: E721
370375

371-
# logging.info("[pytest_runtest_makereport][#002][{0}][{1}]".format(item.name, call.when))
372-
373376
rep: pytest.TestReport = outcome.get_result()
374377
assert rep is not None
375378
assert type(rep) == pytest.TestReport # noqa: E721
@@ -503,7 +506,13 @@ def pytest_configure(config: pytest.Config) -> None:
503506

504507
log_path.mkdir(exist_ok=True)
505508

506-
logging_plugin = config.pluginmanager.get_plugin("logging-plugin")
509+
logging_plugin: _pytest.logging.LoggingPlugin = config.pluginmanager.get_plugin(
510+
"logging-plugin"
511+
)
512+
513+
assert logging_plugin is not None
514+
assert isinstance(logging_plugin, _pytest.logging.LoggingPlugin)
515+
507516
logging_plugin.set_log_path(str(log_path / log_name))
508517

509518

0 commit comments

Comments
 (0)