diff --git a/test/transactron/testing/test_log.py b/test/transactron/testing/test_log.py index ed16b0a36..d010d012e 100644 --- a/test/transactron/testing/test_log.py +++ b/test/transactron/testing/test_log.py @@ -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" diff --git a/transactron/testing/infrastructure.py b/transactron/testing/infrastructure.py index f902658f2..69ff04160 100644 --- a/transactron/testing/infrastructure.py +++ b/transactron/testing/infrastructure.py @@ -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() @@ -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" @@ -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) @@ -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)