Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore logging handler #716

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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