Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pytest_deadfixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def get_parametrized_fixtures(session, available_fixtures):
for test_function in session.items:
try:
for v in test_function.callspec.params.values():
params_values.append(v)
if isinstance(v, str):
params_values.append(v)
except AttributeError:
continue
return [
Expand Down
33 changes: 33 additions & 0 deletions tests/test_deadfixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,36 @@ def test_a_thing(another_fixture):
# Currently these cases are recognized as a false positive, whereas they shouldn't be.
# Due to the dynamic lookup of the fixture, this is going to be hard to recognize.
assert "some_common_fixture" not in result.stdout.str()


def test_parameterized_fixture_complex_objects(pytester):
pytester.makepyfile(
conftest="""
import pytest

@pytest.fixture
def some_fixture():
return 1
"""
)
pytester.makepyfile(
"""
import pytest

class Trapped:
def __bool__(self):
raise ValueError("Object cannot be checked for truthiness")

class Trap:
def __eq__(self, other):
return Trapped()

@pytest.mark.parametrize('input_value,expected', [(Trap(), 2)])
def test_a_thing(input_value, expected, some_fixture):
assert expected == 2
"""
)

result = pytester.runpytest("--dead-fixtures")

assert result.ret == 0, result.stdout.str()