From e98d6fd24cc04db2c6198ba6d70e7111aa87ba1b Mon Sep 17 00:00:00 2001 From: Nikita Fomichev Date: Mon, 25 Mar 2024 18:39:27 +0100 Subject: [PATCH] integration tests: persist pdb history between test runs Run pytest --pdb. On failure or breakpoint, it will fall back to PDB. Commands written here will be saved to a local file and loaded at the start of the next test run. --- .gitignore | 3 +++ tests/integration/conftest.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/.gitignore b/.gitignore index 1ea8f83dcc2..db3f77d7d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -164,6 +164,9 @@ tests/queries/0_stateless/*.generated-expect tests/queries/0_stateless/*.expect.history tests/integration/**/_gen +# pytest --pdb history +.pdb_history + # rust /rust/**/target* # It is autogenerated from *.in diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index a4b18ff523a..f4be31cc532 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -13,6 +13,34 @@ from helpers.network import _NetworkManager logging.raiseExceptions = False +@pytest.fixture(scope="session", autouse=True) +def pdb_history(request): + """ + Fixture loads and saves pdb history to file, so it can be preserved between runs + """ + if request.config.getoption("--pdb"): + import readline # pylint:disable=import-outside-toplevel + import pdb # pylint:disable=import-outside-toplevel + + def save_history(): + readline.write_history_file(".pdb_history") + + def load_history(): + try: + readline.read_history_file(".pdb_history") + except FileNotFoundError: + pass + + load_history() + pdb.Pdb.use_rawinput = True + + yield + + save_history() + else: + yield + + @pytest.fixture(autouse=True, scope="session") def tune_local_port_range(): # Lots of services uses non privileged ports: