Revert "Revert "Moved the code from tests into the main module, and tried to monkey-patch check_output.  Not currently working.""

This reverts commit a3f37447cd65b68b4382f49a8fdc2f66866954d7.