Skip to content

faker_seed fixture crashes with TypeError when plugin is disabled via -p no:randomly #718

@mojosan77

Description

@mojosan77

Bug

The faker_seed autouse fixture in 4.0.x crashes when the plugin is disabled via -p no:randomly.

Version: 4.0.1 (also affects 4.0.0)

Error

TypeError: can only concatenate str (not "int") to str

At src/pytest_randomly/__init__.py:269:

@fixture(autouse=True)
def faker_seed(pytestconfig: Config, request: SubRequest) -> int:
    result: int = pytestconfig.getoption("randomly_seed") + _crc32(
        request.node.nodeid
    )
    return result

Root cause

When the plugin is disabled via -p no:randomly, pytest_configure never runs, so config.option.randomly_seed is never resolved from its default value "default" (a string, via seed_type()) to an int (via make_seed()).

The faker_seed fixture is registered at module level (guarded by have_faker, not by plugin state), so it still runs even when the plugin is disabled. It then attempts "default" + _crc32(...), which is a str + int operation.

Reproduction

pip install pytest-randomly==4.0.1 faker factory-boy
pytest -p no:randomly tests/

Every test fails at fixture setup with the TypeError.

Expected behavior

When the plugin is disabled, the faker_seed fixture should either:

  1. Not be registered, or
  2. Handle the case where the seed hasn't been resolved to an int

Worked in 3.x

In 3.x there was no per-test CRC32 arithmetic on the seed, so the string default was never used in an addition operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions