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

Commit0470d30

Browse files
conftest is updated (#260)
- the calls of logging.root.handle are handled (LogWrapper2)- critical errors are processed
1 parentd48477d commit0470d30

File tree

1 file changed

+100
-100
lines changed

1 file changed

+100
-100
lines changed

‎tests/conftest.py

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ def helper__build_test_id(item: pytest.Function) -> str:
338338

339339
g_error_msg_count_key=pytest.StashKey[int]()
340340
g_warning_msg_count_key=pytest.StashKey[int]()
341+
g_critical_msg_count_key=pytest.StashKey[int]()
341342

342343
# /////////////////////////////////////////////////////////////////////////////
343344

@@ -413,10 +414,17 @@ def helper__makereport__call(
413414
asserttype(outcome)==pluggy.Result# noqa: E721
414415

415416
# --------
416-
item_error_msg_count=item.stash.get(g_error_msg_count_key,0)
417-
asserttype(item_error_msg_count)==int# noqa: E721
418-
assertitem_error_msg_count>=0
417+
item_error_msg_count1=item.stash.get(g_error_msg_count_key,0)
418+
asserttype(item_error_msg_count1)==int# noqa: E721
419+
assertitem_error_msg_count1>=0
419420

421+
item_error_msg_count2=item.stash.get(g_critical_msg_count_key,0)
422+
asserttype(item_error_msg_count2)==int# noqa: E721
423+
assertitem_error_msg_count2>=0
424+
425+
item_error_msg_count=item_error_msg_count1+item_error_msg_count2
426+
427+
# --------
420428
item_warning_msg_count=item.stash.get(g_warning_msg_count_key,0)
421429
asserttype(item_warning_msg_count)==int# noqa: E721
422430
assertitem_warning_msg_count>=0
@@ -600,103 +608,87 @@ def pytest_runtest_makereport(item: pytest.Function, call: pytest.CallInfo):
600608
# /////////////////////////////////////////////////////////////////////////////
601609

602610

603-
classLogErrorWrapper2:
611+
classLogWrapper2:
604612
_old_method:any
605-
_counter:typing.Optional[int]
613+
_err_counter:typing.Optional[int]
614+
_warn_counter:typing.Optional[int]
615+
616+
_critical_counter:typing.Optional[int]
606617

607618
# --------------------------------------------------------------------
608619
def__init__(self):
609620
self._old_method=None
610-
self._counter=None
621+
self._err_counter=None
622+
self._warn_counter=None
623+
624+
self._critical_counter=None
611625

612626
# --------------------------------------------------------------------
613627
def__enter__(self):
614628
assertself._old_methodisNone
615-
assertself._counterisNone
616-
617-
self._old_method=logging.error
618-
self._counter=0
619-
620-
logging.error=self
621-
returnself
622-
623-
# --------------------------------------------------------------------
624-
def__exit__(self,exc_type,exc_val,exc_tb):
625-
assertself._old_methodisnotNone
626-
assertself._counterisnotNone
627-
628-
assertlogging.errorisself
629-
630-
logging.error=self._old_method
631-
632-
self._old_method=None
633-
self._counter=None
634-
returnFalse
635-
636-
# --------------------------------------------------------------------
637-
def__call__(self,*args,**kwargs):
638-
assertself._old_methodisnotNone
639-
assertself._counterisnotNone
640-
641-
asserttype(self._counter)==int# noqa: E721
642-
assertself._counter>=0
643-
644-
r=self._old_method(*args,**kwargs)
645-
646-
self._counter+=1
647-
assertself._counter>0
648-
649-
returnr
650-
651-
652-
# /////////////////////////////////////////////////////////////////////////////
629+
assertself._err_counterisNone
630+
assertself._warn_counterisNone
653631

632+
assertself._critical_counterisNone
654633

655-
classLogWarningWrapper2:
656-
_old_method:any
657-
_counter:typing.Optional[int]
634+
assertlogging.rootisnotNone
635+
assertisinstance(logging.root,logging.RootLogger)
658636

659-
# --------------------------------------------------------------------
660-
def__init__(self):
661-
self._old_method=None
662-
self._counter=None
637+
self._old_method=logging.root.handle
638+
self._err_counter=0
639+
self._warn_counter=0
663640

664-
# --------------------------------------------------------------------
665-
def__enter__(self):
666-
assertself._old_methodisNone
667-
assertself._counterisNone
641+
self._critical_counter=0
668642

669-
self._old_method=logging.warning
670-
self._counter=0
671-
672-
logging.warning=self
643+
logging.root.handle=self
673644
returnself
674645

675646
# --------------------------------------------------------------------
676647
def__exit__(self,exc_type,exc_val,exc_tb):
677648
assertself._old_methodisnotNone
678-
assertself._counterisnotNone
649+
assertself._err_counterisnotNone
650+
assertself._warn_counterisnotNone
651+
652+
assertlogging.rootisnotNone
653+
assertisinstance(logging.root,logging.RootLogger)
679654

680-
assertlogging.warningisself
655+
assertlogging.root.handleisself
681656

682-
logging.warning=self._old_method
657+
logging.root.handle=self._old_method
683658

684659
self._old_method=None
685-
self._counter=None
660+
self._err_counter=None
661+
self._warn_counter=None
662+
self._critical_counter=None
686663
returnFalse
687664

688665
# --------------------------------------------------------------------
689-
def__call__(self,*args,**kwargs):
666+
def__call__(self,record:logging.LogRecord):
667+
assertrecordisnotNone
668+
assertisinstance(record,logging.LogRecord)
690669
assertself._old_methodisnotNone
691-
assertself._counterisnotNone
692-
693-
asserttype(self._counter)==int# noqa: E721
694-
assertself._counter>=0
695-
696-
r=self._old_method(*args,**kwargs)
697-
698-
self._counter+=1
699-
assertself._counter>0
670+
assertself._err_counterisnotNone
671+
assertself._warn_counterisnotNone
672+
assertself._critical_counterisnotNone
673+
674+
asserttype(self._err_counter)==int# noqa: E721
675+
assertself._err_counter>=0
676+
asserttype(self._warn_counter)==int# noqa: E721
677+
assertself._warn_counter>=0
678+
asserttype(self._critical_counter)==int# noqa: E721
679+
assertself._critical_counter>=0
680+
681+
r=self._old_method(record)
682+
683+
ifrecord.levelno==logging.ERROR:
684+
self._err_counter+=1
685+
assertself._err_counter>0
686+
elifrecord.levelno==logging.WARNING:
687+
self._warn_counter+=1
688+
assertself._warn_counter>0
689+
elifrecord.levelno==logging.CRITICAL:
690+
self._critical_counter+=1
691+
assertself._critical_counter>0
700692

701693
returnr
702694

@@ -717,6 +709,13 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function):
717709
assertpyfuncitemisnotNone
718710
assertisinstance(pyfuncitem,pytest.Function)
719711

712+
assertlogging.rootisnotNone
713+
assertisinstance(logging.root,logging.RootLogger)
714+
assertlogging.root.handleisnotNone
715+
716+
debug__log_handle_method=logging.root.handle
717+
assertdebug__log_handle_methodisnotNone
718+
720719
debug__log_error_method=logging.error
721720
assertdebug__log_error_methodisnotNone
722721

@@ -725,55 +724,56 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function):
725724

726725
pyfuncitem.stash[g_error_msg_count_key]=0
727726
pyfuncitem.stash[g_warning_msg_count_key]=0
727+
pyfuncitem.stash[g_critical_msg_count_key]=0
728728

729729
try:
730-
withLogErrorWrapper2()aslogErrorWrapper,LogWarningWrapper2()aslogWarningWrapper:
731-
asserttype(logErrorWrapper)==LogErrorWrapper2# noqa: E721
732-
assertlogErrorWrapper._old_methodisnotNone
733-
asserttype(logErrorWrapper._counter)==int# noqa: E721
734-
assertlogErrorWrapper._counter==0
735-
assertlogging.errorislogErrorWrapper
736-
737-
asserttype(logWarningWrapper)==LogWarningWrapper2# noqa: E721
738-
assertlogWarningWrapper._old_methodisnotNone
739-
asserttype(logWarningWrapper._counter)==int# noqa: E721
740-
assertlogWarningWrapper._counter==0
741-
assertlogging.warningislogWarningWrapper
730+
withLogWrapper2()aslogWrapper:
731+
asserttype(logWrapper)==LogWrapper2# noqa: E721
732+
assertlogWrapper._old_methodisnotNone
733+
asserttype(logWrapper._err_counter)==int# noqa: E721
734+
assertlogWrapper._err_counter==0
735+
asserttype(logWrapper._warn_counter)==int# noqa: E721
736+
assertlogWrapper._warn_counter==0
737+
asserttype(logWrapper._critical_counter)==int# noqa: E721
738+
assertlogWrapper._critical_counter==0
739+
assertlogging.root.handleislogWrapper
742740

743741
r:pluggy.Result=yield
744742

745743
assertrisnotNone
746744
asserttype(r)==pluggy.Result# noqa: E721
747745

748-
assertlogErrorWrapper._old_methodisnotNone
749-
asserttype(logErrorWrapper._counter)==int# noqa: E721
750-
assertlogErrorWrapper._counter>=0
751-
assertlogging.errorislogErrorWrapper
752-
753-
assertlogWarningWrapper._old_methodisnotNone
754-
asserttype(logWarningWrapper._counter)==int# noqa: E721
755-
assertlogWarningWrapper._counter>=0
756-
assertlogging.warningislogWarningWrapper
746+
assertlogWrapper._old_methodisnotNone
747+
asserttype(logWrapper._err_counter)==int# noqa: E721
748+
assertlogWrapper._err_counter>=0
749+
asserttype(logWrapper._warn_counter)==int# noqa: E721
750+
assertlogWrapper._warn_counter>=0
751+
asserttype(logWrapper._critical_counter)==int# noqa: E721
752+
assertlogWrapper._critical_counter>=0
753+
assertlogging.root.handleislogWrapper
757754

758755
assertg_error_msg_count_keyinpyfuncitem.stash
759756
assertg_warning_msg_count_keyinpyfuncitem.stash
757+
assertg_critical_msg_count_keyinpyfuncitem.stash
760758

761759
assertpyfuncitem.stash[g_error_msg_count_key]==0
762760
assertpyfuncitem.stash[g_warning_msg_count_key]==0
761+
assertpyfuncitem.stash[g_critical_msg_count_key]==0
763762

764-
pyfuncitem.stash[g_error_msg_count_key]=logErrorWrapper._counter
765-
pyfuncitem.stash[g_warning_msg_count_key]=logWarningWrapper._counter
763+
pyfuncitem.stash[g_error_msg_count_key]=logWrapper._err_counter
764+
pyfuncitem.stash[g_warning_msg_count_key]=logWrapper._warn_counter
765+
pyfuncitem.stash[g_critical_msg_count_key]=logWrapper._critical_counter
766766

767767
ifr.exceptionisnotNone:
768768
pass
769-
eliflogErrorWrapper._counter==0:
770-
pass
771-
else:
772-
assertlogErrorWrapper._counter>0
769+
eliflogWrapper._err_counter>0:
770+
r.force_exception(SIGNAL_EXCEPTION())
771+
eliflogWrapper._critical_counter>0:
773772
r.force_exception(SIGNAL_EXCEPTION())
774773
finally:
775774
assertlogging.errorisdebug__log_error_method
776775
assertlogging.warningisdebug__log_warning_method
776+
assertlogging.root.handle==debug__log_handle_method
777777
pass
778778

779779

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp