mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Rename _current_method to _current_test
This commit is contained in:
parent
e7f24b7e9c
commit
d7c6fb5dde
@ -277,7 +277,7 @@ class BaseScript:
|
|||||||
self.tests = {} # Mapping of logs for test methods
|
self.tests = {} # Mapping of logs for test methods
|
||||||
self.output = ''
|
self.output = ''
|
||||||
self.failed = False
|
self.failed = False
|
||||||
self._current_method = '' # Tracks the current test method being run (if any)
|
self._current_test = None # Tracks the current test method being run (if any)
|
||||||
|
|
||||||
# Initiate the log
|
# Initiate the log
|
||||||
self.logger = logging.getLogger(f"netbox.scripts.{self.__module__}.{self.__class__.__name__}")
|
self.logger = logging.getLogger(f"netbox.scripts.{self.__module__}.{self.__class__.__name__}")
|
||||||
@ -440,10 +440,10 @@ class BaseScript:
|
|||||||
raise ValueError(f"Invalid logging level: {level}")
|
raise ValueError(f"Invalid logging level: {level}")
|
||||||
|
|
||||||
# A test method is currently active, so log the message using legacy Report logging
|
# A test method is currently active, so log the message using legacy Report logging
|
||||||
if self._current_method:
|
if self._current_test:
|
||||||
|
|
||||||
# TODO: Use a dataclass for test method logs
|
# TODO: Use a dataclass for test method logs
|
||||||
self.tests[self._current_method]['log'].append((
|
self.tests[self._current_test]['log'].append((
|
||||||
timezone.now().isoformat(),
|
timezone.now().isoformat(),
|
||||||
level,
|
level,
|
||||||
str(obj) if obj else None,
|
str(obj) if obj else None,
|
||||||
@ -452,8 +452,8 @@ class BaseScript:
|
|||||||
))
|
))
|
||||||
|
|
||||||
# Increment the event counter for this level
|
# Increment the event counter for this level
|
||||||
if level in self.tests[self._current_method]:
|
if level in self.tests[self._current_test]:
|
||||||
self.tests[self._current_method][level] += 1
|
self.tests[self._current_test][level] += 1
|
||||||
|
|
||||||
elif message:
|
elif message:
|
||||||
|
|
||||||
@ -525,17 +525,16 @@ class BaseScript:
|
|||||||
self.logger.info(f"Running report")
|
self.logger.info(f"Running report")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for method_name in self.tests:
|
for test_name in self.tests:
|
||||||
self._current_method = method_name
|
self._current_test = test_name
|
||||||
test_method = getattr(self, method_name)
|
test_method = getattr(self, test_name)
|
||||||
test_method()
|
test_method()
|
||||||
|
self._current_test = None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
self._current_test = None
|
||||||
self.post_run()
|
self.post_run()
|
||||||
self._current_method = ''
|
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
self._current_method = ''
|
|
||||||
|
|
||||||
def pre_run(self):
|
def pre_run(self):
|
||||||
"""
|
"""
|
||||||
Legacy method for operations performed immediately prior to running a Report.
|
Legacy method for operations performed immediately prior to running a Report.
|
||||||
|
Loading…
Reference in New Issue
Block a user