diff --git a/src/mqt/bench/output.py b/src/mqt/bench/output.py index a196c8a51..9d1158e56 100644 --- a/src/mqt/bench/output.py +++ b/src/mqt/bench/output.py @@ -76,7 +76,7 @@ def generate_header( "The Python package `mqt.bench` is not installed in the current " "environment. Install it with\n\n" " pip install mqt.bench\n\n" - f"and try again. (Original error: {exc})" + "and try again." ) raise MQTBenchExporterError(msg) from exc @@ -155,7 +155,7 @@ def write_circuit( destination.write(header) (dump2 if fmt is OutputFormat.QASM2 else dump3)(qc, destination) except Exception as exc: # pragma: no cover - unforeseen I/O - msg = f"Failed to write QASM stream. (Original error: {exc})" + msg = "Failed to write QASM stream." raise MQTBenchExporterError(msg) from exc return @@ -166,7 +166,7 @@ def write_circuit( try: dump_qpy(_attach_metadata(qc, header), destination) except Exception as exc: - msg = f"Failed to write QPY stream. (Original error: {exc})" + msg = "Failed to write QPY stream." raise MQTBenchExporterError(msg) from exc return @@ -179,7 +179,7 @@ def write_circuit( f.write(header) (dump2 if fmt is OutputFormat.QASM2 else dump3)(qc, f) except Exception as exc: - msg = f"Failed to write {fmt.value.upper()} file to {destination}. (Original error: {exc})" + msg = f"Failed to write {fmt.value.upper()} file to {destination}." raise MQTBenchExporterError(msg) from exc elif fmt is OutputFormat.QPY: @@ -187,7 +187,7 @@ def write_circuit( with destination.open("wb") as f: dump_qpy(_attach_metadata(qc, header), f) except Exception as exc: - msg = f"Failed to write QPY file to {destination}. (Original error: {exc})" + msg = f"Failed to write QPY file to {destination}." raise MQTBenchExporterError(msg) from exc else: @@ -220,7 +220,8 @@ def save_circuit( try: write_circuit(qc, path, level, output_format, target) except MQTBenchExporterError as e: - print(e) + cause = f": {e.__cause__}" if e.__cause__ else "" + print(f"{e}{cause}") return False return True diff --git a/tests/test_bench.py b/tests/test_bench.py index 36b9fd1ee..b8dbd1d42 100644 --- a/tests/test_bench.py +++ b/tests/test_bench.py @@ -668,7 +668,8 @@ def test_generate_header_minimal(monkeypatch: pytest.MonkeyPatch) -> None: hdr = generate_header(OutputFormat.QASM3, BenchmarkLevel.INDEP) lines = hdr.splitlines() # first line has today's date - assert lines[0] == f"// Benchmark created by MQT Bench on {datetime.datetime.now(tz=datetime.timezone.utc).date()}" + today = datetime.datetime.now(tz=datetime.timezone.utc).date() + assert lines[0] == f"// Benchmark created by MQT Bench on {today}" # contains the fixed info lines assert "// For more info: https://mqt-bench.app/" in hdr assert "// MQT Bench version: 9.9.9" in hdr @@ -756,9 +757,8 @@ def test_write_circuit_qpy(tmp_path: Path) -> None: assert isinstance(circ, QuantumCircuit) header = circ.metadata["mqt_bench"] - assert header.startswith( - f"// Benchmark created by MQT Bench on {datetime.datetime.now(tz=datetime.timezone.utc).date()}" - ) + today = datetime.datetime.now(tz=datetime.timezone.utc).date() + assert header.startswith(f"// Benchmark created by MQT Bench on {today}") assert "// MQT Bench version:" in header assert "// Output format: qpy" in header