def verify_output(capsys: CaptureFixture, filename: str) -> None: """ Utility function to ensure output matches file. """ captured, _ = capsys.readouterr() with capsys.disabled(): with open(filename, encoding="utf-8") as output_file: expected = output_file.read() assert captured == expected
def actual_output(capsys: CaptureFixture, caplog: LogCaptureFixture, monkeypatch: MonkeyPatch) -> List[JSONOutputType]: tests.utils.enable_sentry_integration_mode(monkeypatch) with pytest.raises(RuntimeError): with capsys.disabled(): # must import locally to avoid `NameError: name 'sentry_integration' is not defined` will be thrown from docs_src import ( # pylint: disable=import-outside-toplevel sentry_integration, ) caplog.clear() # caplog/capsys reset to prevent duplicate entries tests.docs_src.utils.reload_module_non_dev_local_env( monkeypatch, sentry_integration) tests.docs_src.utils.redirect_captured_logs_to_stdout(caplog) return tests.docs_src.utils.get_validated_json_output(capsys)
def test_multiline_diff(locker: Locker, capsys: CaptureFixture) -> None: rhyme = "\n".join(x.strip() for x in """ This rhyme rhyme Is multi-line Observe, the difference printing is sublime\n Even after a blank line """.strip().split("\n")) with patch("builtins.input", lambda *args: "n"), raises(UserDidNotAcceptDataException): locker.lock(rhyme, "rhyme") captured = capsys.readouterr() captured_out = captured.out with capsys.disabled(): locker.lock(captured_out, "rhyme_diff")