Skip to content

v1.0.1

Latest
Compare
Choose a tag to compare
@Athroniaeth Athroniaeth released this 03 Feb 21:26

Patch lock.lock

if not tuple is given in lock.lock and that arguments was given directly, throw exception.

Problem:

import pytest
from pytest_lock import FixtureLock


def sum_(list_numbers):
    if not list_numbers:
        raise ValueError("The list is empty")
    return sum(list_numbers)


@pytest.mark.parametrize("list_numbers", (
    [1, 2, 3],
    [1, 2, 3, 4],
    [1, 2, 3, 4, 5],
    []
))
def test_sum(lock: FixtureLock, list_numbers):
    lock.lock(sum_, list_numbers)
pytest --lock
pytest 

Pytest-lock will work but with this modification.

def sum_(list_numbers):
    if not list_numbers:
        raise ValueError("The list is empty")
    return sum(list_numbers) + 1000

The test will always passed. The reason is because lock.lock wait a Tuple of arguments (no need to have *args and **kwargs in function) but if you give a Sequence, pytest-lock don't will understand and will still try to make the code work. Now if you don't wrap your arguments in a tuple an error will be thrown