Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc18e5b

Browse files
conftest.py is updated [refactoring] (#226)
New code can process a failure in fixtures and builds a list of these cases (achtung tests).
1 parent76fa94c commitbc18e5b

File tree

1 file changed

+98
-48
lines changed

1 file changed

+98
-48
lines changed

‎tests/conftest.py

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

4-
import_pytest.outcomes
5-
64
importpluggy
75
importpytest
8-
import_pytest
96
importos
107
importlogging
118
importpathlib
129
importmath
1310
importdatetime
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

@@ -109,10 +106,12 @@ class TEST_PROCESS_STATS:
109106
cSkippedTests:int=0
110107
cNotXFailedTests:int=0
111108
cUnexpectedTests:int=0
109+
cAchtungTests:int=0
112110

113111
FailedTests=list[str]()
114112
XFailedTests=list[str]()
115113
NotXFailedTests=list[str]()
114+
AchtungTests=list[str]()
116115

117116
# --------------------------------------------------------------------
118117
defincrementTotalTestCount()->None:
@@ -163,6 +162,14 @@ def incrementNotXFailedTests(testID: str) -> None:
163162
defincrementUnexpectedTests()->None:
164163
__class__.cUnexpectedTests+=1
165164

165+
# --------------------------------------------------------------------
166+
defincrementAchtungTestCount(testID:str)->None:
167+
asserttype(testID)==str# noqa: E721
168+
asserttype(__class__.AchtungTests)==list# noqa: E721
169+
170+
__class__.AchtungTests.append(testID)# raise?
171+
__class__.cAchtungTests+=1
172+
166173

167174
# /////////////////////////////////////////////////////////////////////////////
168175

@@ -198,10 +205,13 @@ def helper__makereport__setup(
198205
assertitemisnotNone
199206
assertcallisnotNone
200207
assertoutcomeisnotNone
201-
asserttype(item)==pytest.Function# noqa: E721
208+
# it may be pytest.Function or _pytest.unittest.TestCaseFunction
209+
assertisinstance(item,pytest.Function)
202210
asserttype(call)==pytest.CallInfo# noqa: E721
203211
asserttype(outcome)==pluggy.Result# noqa: E721
204212

213+
C_LINE1="******************************************************"
214+
205215
# logging.info("pytest_runtest_makereport - setup")
206216

207217
TEST_PROCESS_STATS.incrementTotalTestCount()
@@ -214,26 +224,42 @@ def helper__makereport__setup(
214224
TEST_PROCESS_STATS.incrementNotExecutedTestCount()
215225
return
216226

217-
assertrep.outcome=="passed"
218-
219-
testNumber=TEST_PROCESS_STATS.incrementExecutedTestCount()
220-
221227
testID=""
222228

223229
ifitem.clsisnotNone:
224230
testID=item.cls.__module__+"."+item.cls.__name__+"::"
225231

226232
testID=testID+item.name
227233

228-
iftestNumber>1:
229-
logging.info("")
234+
ifrep.outcome=="passed":
235+
testNumber=TEST_PROCESS_STATS.incrementExecutedTestCount()
236+
237+
logging.info(C_LINE1)
238+
logging.info("* START TEST {0}".format(testID))
239+
logging.info("*")
240+
logging.info("* Path : {0}".format(item.path))
241+
logging.info("* Number: {0}".format(testNumber))
242+
logging.info("*")
243+
return
244+
245+
assertrep.outcome!="passed"
246+
247+
TEST_PROCESS_STATS.incrementAchtungTestCount(testID)
230248

231-
logging.info("******************************************************")
232-
logging.info("*START TEST {0}".format(testID))
249+
logging.info(C_LINE1)
250+
logging.info("*ACHTUNG TEST {0}".format(testID))
233251
logging.info("*")
234252
logging.info("* Path : {0}".format(item.path))
235-
logging.info("* Number: {0}".format(testNumber))
253+
logging.info("* Outcome is [{0}]".format(rep.outcome))
254+
255+
ifrep.outcome=="failed":
256+
assertcall.excinfoisnotNone
257+
assertcall.excinfo.valueisnotNone
258+
logging.info("*")
259+
logging.error(call.excinfo.value)
260+
236261
logging.info("*")
262+
return
237263

238264

239265
# ------------------------------------------------------------------------
@@ -243,12 +269,11 @@ def helper__makereport__call(
243269
assertitemisnotNone
244270
assertcallisnotNone
245271
assertoutcomeisnotNone
246-
asserttype(item)==pytest.Function# noqa: E721
272+
# it may be pytest.Function or _pytest.unittest.TestCaseFunction
273+
assertisinstance(item,pytest.Function)
247274
asserttype(call)==pytest.CallInfo# noqa: E721
248275
asserttype(outcome)==pluggy.Result# noqa: E721
249276

250-
# logging.info("pytest_runtest_makereport - call")
251-
252277
rep=outcome.get_result()
253278
assertrepisnotNone
254279
asserttype(rep)==pytest.TestReport# noqa: E721
@@ -341,7 +366,8 @@ def helper__makereport__call(
341366
else:
342367
TEST_PROCESS_STATS.incrementUnexpectedTests()
343368
exitStatus="UNEXPECTED [{0}]".format(rep.outcome)
344-
assertFalse
369+
# [2025-03-28] It may create a useless problem in new environment.
370+
# assert False
345371

346372
# --------
347373
logging.info("*")
@@ -350,6 +376,7 @@ def helper__makereport__call(
350376
logging.info("* EXIT STATUS : {0}".format(exitStatus))
351377
logging.info("*")
352378
logging.info("* STOP TEST {0}".format(testID))
379+
logging.info("*")
353380

354381

355382
# /////////////////////////////////////////////////////////////////////////////
@@ -359,17 +386,14 @@ def helper__makereport__call(
359386
defpytest_runtest_makereport(item:pytest.Function,call:pytest.CallInfo):
360387
assertitemisnotNone
361388
assertcallisnotNone
362-
asserttype(item)==pytest.Function# noqa: E721
389+
# it may be pytest.Function or _pytest.unittest.TestCaseFunction
390+
assertisinstance(item,pytest.Function)
363391
asserttype(call)==pytest.CallInfo# noqa: E721
364392

365-
# logging.info("[pytest_runtest_makereport][#001][{0}][{1}]".format(item.name, call.when))
366-
367393
outcome:pluggy.Result=yield
368394
assertoutcomeisnotNone
369395
asserttype(outcome)==pluggy.Result# noqa: E721
370396

371-
# logging.info("[pytest_runtest_makereport][#002][{0}][{1}]".format(item.name, call.when))
372-
373397
rep:pytest.TestReport=outcome.get_result()
374398
assertrepisnotNone
375399
asserttype(rep)==pytest.TestReport# noqa: E721
@@ -440,41 +464,61 @@ def run_after_tests(request: pytest.FixtureRequest):
440464

441465
yield
442466

443-
logging.info("--------------------------- [FAILED TESTS]")
444-
logging.info("")
445-
446-
assertlen(TEST_PROCESS_STATS.FailedTests)==TEST_PROCESS_STATS.cFailedTests
447-
448-
iflen(TEST_PROCESS_STATS.FailedTests)>0:
449-
helper__print_test_list(TEST_PROCESS_STATS.FailedTests)
450-
logging.info("")
467+
C_LINE1="---------------------------"
451468

452-
logging.info("--------------------------- [XFAILED TESTS]")
453-
logging.info("")
469+
defLOCAL__print_line1_with_header(header:str):
470+
asserttype(C_LINE1)==str# noqa: E721
471+
asserttype(header)==str# noqa: E721
472+
assertheader!=""
473+
logging.info(C_LINE1+" ["+header+"]")
454474

455-
assertlen(TEST_PROCESS_STATS.XFailedTests)==TEST_PROCESS_STATS.cXFailedTests
475+
defLOCAL__print_test_list(header:str,test_count:int,test_list:list[str]):
476+
asserttype(header)==str# noqa: E721
477+
asserttype(test_count)==int# noqa: E721
478+
asserttype(test_list)==list# noqa: E721
479+
assertheader!=""
480+
asserttest_count>=0
481+
assertlen(test_list)==test_count
456482

457-
iflen(TEST_PROCESS_STATS.XFailedTests)>0:
458-
helper__print_test_list(TEST_PROCESS_STATS.XFailedTests)
483+
LOCAL__print_line1_with_header(header)
459484
logging.info("")
485+
iflen(test_list)>0:
486+
helper__print_test_list(test_list)
487+
logging.info("")
488+
489+
# fmt: off
490+
LOCAL__print_test_list(
491+
"ACHTUNG TESTS",
492+
TEST_PROCESS_STATS.cAchtungTests,
493+
TEST_PROCESS_STATS.AchtungTests,
494+
)
460495

461-
logging.info("--------------------------- [NOT XFAILED TESTS]")
462-
logging.info("")
496+
LOCAL__print_test_list(
497+
"FAILED TESTS",
498+
TEST_PROCESS_STATS.cFailedTests,
499+
TEST_PROCESS_STATS.FailedTests
500+
)
463501

464-
assert (
465-
len(TEST_PROCESS_STATS.NotXFailedTests)==TEST_PROCESS_STATS.cNotXFailedTests
502+
LOCAL__print_test_list(
503+
"XFAILED TESTS",
504+
TEST_PROCESS_STATS.cXFailedTests,
505+
TEST_PROCESS_STATS.XFailedTests,
466506
)
467507

468-
iflen(TEST_PROCESS_STATS.NotXFailedTests)>0:
469-
helper__print_test_list(TEST_PROCESS_STATS.NotXFailedTests)
470-
logging.info("")
508+
LOCAL__print_test_list(
509+
"NOT XFAILED TESTS",
510+
TEST_PROCESS_STATS.cNotXFailedTests,
511+
TEST_PROCESS_STATS.NotXFailedTests,
512+
)
513+
# fmt: on
471514

472-
logging.info("--------------------------- [SUMMARY STATISTICS]")
515+
LOCAL__print_line1_with_header("SUMMARY STATISTICS")
473516
logging.info("")
474517
logging.info("[TESTS]")
475518
logging.info(" TOTAL : {0}".format(TEST_PROCESS_STATS.cTotalTests))
476519
logging.info(" EXECUTED : {0}".format(TEST_PROCESS_STATS.cExecutedTests))
477520
logging.info(" NOT EXECUTED: {0}".format(TEST_PROCESS_STATS.cNotExecutedTests))
521+
logging.info(" ACHTUNG : {0}".format(TEST_PROCESS_STATS.cAchtungTests))
478522
logging.info("")
479523
logging.info(" PASSED : {0}".format(TEST_PROCESS_STATS.cPassedTests))
480524
logging.info(" FAILED : {0}".format(TEST_PROCESS_STATS.cFailedTests))
@@ -503,7 +547,13 @@ def pytest_configure(config: pytest.Config) -> None:
503547

504548
log_path.mkdir(exist_ok=True)
505549

506-
logging_plugin=config.pluginmanager.get_plugin("logging-plugin")
550+
logging_plugin:_pytest.logging.LoggingPlugin=config.pluginmanager.get_plugin(
551+
"logging-plugin"
552+
)
553+
554+
assertlogging_pluginisnotNone
555+
assertisinstance(logging_plugin,_pytest.logging.LoggingPlugin)
556+
507557
logging_plugin.set_log_path(str(log_path/log_name))
508558

509559

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp