From a4868f0669b3fd01cb357193e2ebd1d449f6078b Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Mon, 24 Feb 2025 15:18:51 +0200 Subject: [PATCH 1/4] Skip specific snapshot paths when running tests against non-local versions of LS --- README.md | 12 +++++++++++- localstack_snapshot/pytest/snapshot.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f041c8..7241078 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,20 @@ This project is in a very early stage and will be both restructured and renamed. ## Quickstart -to install the python and other developer requirements into a venv run: +To install the python and other developer requirements into a venv run: make install +#### Usable env vars + +There's a few env vars that can be used with this project: + +* `TEST_TARGET`: Set to `AWS_CLOUD` to use an externally-deployed instance when running tests. +* `TEST_FORCE_SNAPSHOT_SKIP_VERIFY`: Set to `1` to force applying the snapshot filters regardless of what `TEST_TARGET` is set to. +* `SNAPSHOT_LEGACY_REPORT`: By default set to `0`. Can be set to `1`. +* `SNAPSHOT_UDPATE`: By default set to `0`. Can be set to `1`. +* `SNAPSHOT_RAW`: By default set to `0`. Can be set to `1`. + ## Format code We use black and isort as code style tools. diff --git a/localstack_snapshot/pytest/snapshot.py b/localstack_snapshot/pytest/snapshot.py index c6885d1..1c6656b 100644 --- a/localstack_snapshot/pytest/snapshot.py +++ b/localstack_snapshot/pytest/snapshot.py @@ -20,6 +20,14 @@ def is_aws(): return os.environ.get("TEST_TARGET", "") == "AWS_CLOUD" +def force_skipping_snapshot_verify(): + """ + Forces skipping verification according to the snapshot configuration. + Useful when is_aws() evaluates to True, but the target is actually an LS instance. + """ + return os.environ.get("TEST_FORCE_SNAPSHOT_SKIP_VERIFY", "") == "1" + + @pytest.hookimpl def pytest_configure(config: Config): config.addinivalue_line("markers", "skip_snapshot_verify") @@ -68,7 +76,9 @@ def pytest_runtest_call(item: Item) -> None: verify = True paths = [] - if not is_aws(): # only skip for local tests + if ( + not is_aws() or force_skipping_snapshot_verify() + ): # only skip for local tests unless overridden for m in item.iter_markers(name="skip_snapshot_verify"): skip_paths = m.kwargs.get("paths", []) From 6dea3d3d6689e7f6594ed0f95f2a1e29a7ed81f4 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 25 Feb 2025 16:56:06 +0200 Subject: [PATCH 2/4] Update README.md Co-authored-by: Daniel Fangl --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7241078..4c0a0a9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ To install the python and other developer requirements into a venv run: make install -#### Usable env vars +### Configuration options There's a few env vars that can be used with this project: From 9501f38c989fa4577092a38697692e2b58c82d77 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 25 Feb 2025 16:57:36 +0200 Subject: [PATCH 3/4] Remove TEST_FORCE_SNAPSHOT_SKIP_VERIFY --- README.md | 1 - localstack_snapshot/pytest/snapshot.py | 11 +---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/README.md b/README.md index 4c0a0a9..327db5e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ To install the python and other developer requirements into a venv run: There's a few env vars that can be used with this project: * `TEST_TARGET`: Set to `AWS_CLOUD` to use an externally-deployed instance when running tests. -* `TEST_FORCE_SNAPSHOT_SKIP_VERIFY`: Set to `1` to force applying the snapshot filters regardless of what `TEST_TARGET` is set to. * `SNAPSHOT_LEGACY_REPORT`: By default set to `0`. Can be set to `1`. * `SNAPSHOT_UDPATE`: By default set to `0`. Can be set to `1`. * `SNAPSHOT_RAW`: By default set to `0`. Can be set to `1`. diff --git a/localstack_snapshot/pytest/snapshot.py b/localstack_snapshot/pytest/snapshot.py index 1c6656b..e27ce5d 100644 --- a/localstack_snapshot/pytest/snapshot.py +++ b/localstack_snapshot/pytest/snapshot.py @@ -20,13 +20,6 @@ def is_aws(): return os.environ.get("TEST_TARGET", "") == "AWS_CLOUD" -def force_skipping_snapshot_verify(): - """ - Forces skipping verification according to the snapshot configuration. - Useful when is_aws() evaluates to True, but the target is actually an LS instance. - """ - return os.environ.get("TEST_FORCE_SNAPSHOT_SKIP_VERIFY", "") == "1" - @pytest.hookimpl def pytest_configure(config: Config): @@ -76,9 +69,7 @@ def pytest_runtest_call(item: Item) -> None: verify = True paths = [] - if ( - not is_aws() or force_skipping_snapshot_verify() - ): # only skip for local tests unless overridden + if not is_aws(): # only skip for local tests unless overridden for m in item.iter_markers(name="skip_snapshot_verify"): skip_paths = m.kwargs.get("paths", []) From 6ce1cea36831831d3d7f8b032f4e55c7f98599a9 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 25 Feb 2025 16:58:14 +0200 Subject: [PATCH 4/4] Format --- localstack_snapshot/pytest/snapshot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/localstack_snapshot/pytest/snapshot.py b/localstack_snapshot/pytest/snapshot.py index e27ce5d..c6885d1 100644 --- a/localstack_snapshot/pytest/snapshot.py +++ b/localstack_snapshot/pytest/snapshot.py @@ -20,7 +20,6 @@ def is_aws(): return os.environ.get("TEST_TARGET", "") == "AWS_CLOUD" - @pytest.hookimpl def pytest_configure(config: Config): config.addinivalue_line("markers", "skip_snapshot_verify") @@ -69,7 +68,7 @@ def pytest_runtest_call(item: Item) -> None: verify = True paths = [] - if not is_aws(): # only skip for local tests unless overridden + if not is_aws(): # only skip for local tests for m in item.iter_markers(name="skip_snapshot_verify"): skip_paths = m.kwargs.get("paths", [])