From c074dafba38fab2490b66816913f582a0e9d07f8 Mon Sep 17 00:00:00 2001 From: Zac Hatfield-Dodds Date: Wed, 25 Sep 2024 01:30:09 -0700 Subject: [PATCH] Compat with newer pytest --- docs-src/changelog.md | 4 +++- src/hypofuzz/interface.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs-src/changelog.md b/docs-src/changelog.md index b838d1a..dcaabd4 100644 --- a/docs-src/changelog.md +++ b/docs-src/changelog.md @@ -2,8 +2,10 @@ HypoFuzz uses [calendar-based versioning](https://calver.org/), with a `YY-MM-patch` format. +Fixed compatibility with Pytest 8.1 ([#35](https://github.com/Zac-HD/hypofuzz/issues/35)). + ## 24.02.3 -Fixed compatibility with Pytest 8.x ([#32](https://github.com/Zac-HD/hypofuzz/issues/32)). +Fixed compatibility with Pytest 8.0 ([#32](https://github.com/Zac-HD/hypofuzz/issues/32)). ## 24.02.2 Fixed a dashboard bug ([#31](https://github.com/Zac-HD/hypofuzz/issues/31)). diff --git a/src/hypofuzz/interface.py b/src/hypofuzz/interface.py index 3d1ad42..e1dbd8a 100644 --- a/src/hypofuzz/interface.py +++ b/src/hypofuzz/interface.py @@ -5,7 +5,7 @@ from contextlib import redirect_stdout, suppress from functools import partial from inspect import signature -from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple +from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, get_type_hints import pytest import requests @@ -21,7 +21,7 @@ class _ItemsCollector: """A pytest plugin which grabs all the fuzzable tests at the end of collection.""" def __init__(self) -> None: - self.fuzz_targets: List["FuzzProcess"] = [] + self.fuzz_targets: List[FuzzProcess] = [] def pytest_collection_finish(self, session: pytest.Session) -> None: from .hy import FuzzProcess @@ -37,7 +37,13 @@ def pytest_collection_finish(self, session: pytest.Session) -> None: # until we get full pytest compatibility it's an expedient approximation. # The relevant internals changed in Pytest 8.0, so handle both cases... if "ignore_args" in signature(manager.getfixtureclosure).parameters: - all_autouse = set(manager._getautousenames(item.nodeid)) + from _pytest.nodes import Node + + if get_type_hints(manager._getautousenames).get("node") == Node: + # from pytest 8.3 or thereabouts + all_autouse = set(manager._getautousenames(item)) + else: + all_autouse = set(manager._getautousenames(item.nodeid)) else: _, all_autouse, _ = manager.getfixtureclosure( tuple(manager._getautousenames(item.nodeid)), item