From 90d85308cbb36418be0dd2b313ce39a55848e570 Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Sun, 23 Apr 2023 15:19:18 -0500 Subject: [PATCH] Skip memray tests if not installed --- dev-requirements.txt | 3 +-- noxfile.py | 4 +++- tests/test_memory.py | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index c16958c..c21833d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -8,5 +8,4 @@ trustme requests flaky httpx -memray -pytest-memray +pytest-memray; python_version<"3.12" and sys_platform!="win32" and implementation_name=="cpython" diff --git a/noxfile.py b/noxfile.py index 027b148..9a3fccf 100644 --- a/noxfile.py +++ b/noxfile.py @@ -52,12 +52,14 @@ def test(session): session.install("-rdev-requirements.txt", ".") session.run("pip", "freeze") + memray_supported = not session.run("python", "-c", '"import pytest_memray"') + session.run( "pytest", "-v", "-s", "-rs", - "--memray", + *("--memray", "--hide-memray-summary") if memray_supported else (), "--no-flaky-report", "--max-runs=3", *(session.posargs or ("tests/",)), diff --git a/tests/test_memory.py b/tests/test_memory.py index 18cb24a..a56b404 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -8,7 +8,15 @@ from .conftest import Server +try: + import pytest_memray # noqa: F401 + memray_installed = True +except ImportError: + memray_installed = False + + +@pytest.mark.skipif(not memray_installed, reason="Memray isn't installed") @pytest.mark.limit_memory("1MB") @pytest.mark.asyncio async def test_memory_limit(server: Server) -> None: