From fedbcab274e6a5ae36e25bf11cc6b2b92d6e09dc Mon Sep 17 00:00:00 2001 From: Emin Martinian Date: Sat, 23 Aug 2025 11:49:20 -0400 Subject: [PATCH] Patch to maybe show testing outputs if not in reference --- nbval/plugin.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nbval/plugin.py b/nbval/plugin.py index ee3ff29..5938b1b 100644 --- a/nbval/plugin.py +++ b/nbval/plugin.py @@ -478,6 +478,8 @@ def compare_outputs(self, test, ref, skip_compare=None): cc.FAIL + "Unexpected output fields from running code: %s" % (test_keys - ref_keys) + + self.maybe_show_output_mismatch(testing_outs, + reference_outs) + cc.ENDC ) return False @@ -520,6 +522,19 @@ def compare_outputs(self, test, ref, skip_compare=None): return False return True + def maybe_show_output_mismatch(self, testing_outs, reference_outs, + verbosity_for_show=3): + """Show testing outputs not in reference outputs based on verbosity. + """ + if self.config.get_verbosity() >= verbosity_for_show: + result = [] + for stream, contents in testing_outs.items(): + if stream not in reference_outs: + result.append( + f'\n{stream} in test but not in reference: {contents}\n') + return '\n'.join(result) + return '' + def format_output_compare(self, key, left, right): """Format an output for printing""" if isinstance(left, str):