Skip to content

Commit

Permalink
Restore logging handler (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Urbańczyk authored Jun 26, 2024
1 parent 6250e2d commit e454132
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion test/transactron/testing/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def proc():
with self.run_simulation(m) as sim:
sim.add_sync_process(proc)

print(caplog.text)
assert (
"WARNING test_logger:logging.py:83 [test/transactron/testing/test_log.py:22] "
+ "Log triggered under Amaranth If value+3=0x2d"
Expand Down
23 changes: 13 additions & 10 deletions transactron/testing/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ def run(self) -> bool:
class TestCaseWithSimulator:
dependency_manager: DependencyManager

@pytest.fixture(scope="session")
def register_logging_handler(self):
root_logger = logging.getLogger()
ch = logging.StreamHandler()
formatter = _LogFormatter()
ch.setFormatter(formatter)
root_logger.handlers += [ch]

@contextmanager
def configure_dependency_context(self):
self.dependency_manager = DependencyManager()
Expand Down Expand Up @@ -266,6 +258,7 @@ def f():
os.makedirs(profile_dir, exist_ok=True)
profile.encode(f"{profile_dir}/{profile_file}.json")

@contextmanager
def configure_logging(self):
def on_error():
assert False, "Simulation finished due to an error"
Expand All @@ -274,6 +267,16 @@ def on_error():
log_filter = os.environ["__TRANSACTRON_LOG_FILTER"]
self._transactron_sim_processes_to_add.append(lambda: make_logging_process(log_level, log_filter, on_error))

ch = logging.StreamHandler()
formatter = _LogFormatter()
ch.setFormatter(formatter)

root_logger = logging.getLogger()
handlers_before = root_logger.handlers.copy()
root_logger.handlers.append(ch)
yield
root_logger.handlers = handlers_before

@contextmanager
def reinitialize_fixtures(self):
# File name to be used in the current test run (either standard or hypothesis iteration)
Expand All @@ -287,8 +290,8 @@ def reinitialize_fixtures(self):
with self.configure_dependency_context():
self.configure_traces()
with self.configure_profiles():
self.configure_logging()
yield
with self.configure_logging():
yield
self._transactron_hypothesis_iter_counter += 1

@pytest.fixture(autouse=True)
Expand Down

0 comments on commit e454132

Please sign in to comment.