Prechádzať zdrojové kódy

hide deprecation warning in pytests for now

Falko Schindler 1 rok pred
rodič
commit
a0ddb19e7d
2 zmenil súbory, kde vykonal 9 pridanie a 3 odobranie
  1. 4 3
      nicegui/events.py
  2. 5 0
      nicegui/helpers.py

+ 4 - 3
nicegui/events.py

@@ -3,7 +3,7 @@ from inspect import Parameter, signature
 from typing import TYPE_CHECKING, Any, Awaitable, BinaryIO, Callable, Dict, List, Optional
 
 from . import background_tasks, globals
-from .helpers import KWONLY_SLOTS
+from .helpers import KWONLY_SLOTS, is_pytest
 
 if TYPE_CHECKING:
     from .client import Client
@@ -22,8 +22,9 @@ class GenericEventArguments(EventArguments):
 
     def __getitem__(self, key: str) -> Any:
         if key == 'args':
-            globals.log.warning('msg["args"] is deprecated, use e.args instead '
-                                '(see https://github.com/zauberzeug/nicegui/pull/1095)')
+            if not is_pytest():  # TODO: remove this check after updating all demos and examples
+                globals.log.warning('msg["args"] is deprecated, use e.args instead '
+                                    '(see https://github.com/zauberzeug/nicegui/pull/1095)')
             return self.args
         raise KeyError(key)
 

+ 5 - 0
nicegui/helpers.py

@@ -27,6 +27,11 @@ mimetypes.init()
 KWONLY_SLOTS = {'kw_only': True, 'slots': True} if sys.version_info >= (3, 10) else {}
 
 
+def is_pytest() -> bool:
+    """Check if the code is running in pytest."""
+    return 'pytest' in sys.modules
+
+
 def is_coroutine_function(object: Any) -> bool:
     """Check if the object is a coroutine function.