Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
pytest-lazy-fixtures
Advanced tools
Use your fixtures in @pytest.mark.parametrize
.
This project was inspired by pytest-lazy-fixture.
Improvements that have been made in this project:
pip install pytest-lazy-fixtures
To use your fixtures inside @pytest.mark.parametrize
you can use lf
(lazy_fixture
).
import pytest
from pytest_lazy_fixtures import lf
@pytest.fixture()
def one():
return 1
@pytest.mark.parametrize('arg1,arg2', [('val1', lf('one'))])
def test_func(arg1, arg2):
assert arg2 == 1
lf
can be used with any data structures. For example, in the following example, lf
is used in the dictionary:
import pytest
from pytest_lazy_fixtures import lf
@pytest.fixture()
def one():
return 1
@pytest.mark.parametrize('arg1,arg2', [('val1', {"value": lf('one')})])
def test_func(arg1, arg2):
assert arg2 == {"value": 1}
You can also specify getting an attribute through a dot:
import pytest
from pytest_lazy_fixtures import lf
class Entity:
def __init__(self, value):
self.value = value
@pytest.fixture()
def one():
return Entity(1)
@pytest.mark.parametrize('arg1,arg2', [('val1', lf('one.value'))])
def test_func(arg1, arg2):
assert arg2 == 1
And there is some useful wrapper called lfc
(lazy_fixture_callable
).
It can work with any callable and your fixtures, e.g.
import pytest
from pytest_lazy_fixtures import lf, lfc
class Entity:
def __init__(self, value):
self.value = value
def __str__(self) -> str:
return str(self.value)
def sum(self, value: int) -> int:
return self.value + value
@pytest.fixture()
def entity():
return Entity(1)
@pytest.fixture()
def two():
return 2
@pytest.fixture()
def three():
return 3
@pytest.fixture()
def entity_format():
def _entity_format(entity: Entity):
return {"value": entity.value}
return _entity_format
@pytest.mark.parametrize(
"message",
[
lfc(
"There is two lazy fixture args, {} and {}! And one kwarg {field}! And also simple value {simple}".format,
lf("entity"),
lf("two"),
field=lf("three"),
simple="value",
),
],
)
def test_lazy_fixture_callable_with_func(message):
assert message == "There is two lazy fixture args, 1 and 2! And one kwarg 3! And also simple value value"
@pytest.mark.parametrize("formatted", [lfc("entity_format", lf("entity"))])
def test_lazy_fixture_callable_with_lf(formatted, entity):
assert formatted == {"value": entity.value}
@pytest.mark.parametrize("result", [lfc("entity.sum", lf("two"))])
def test_lazy_fixture_callable_with_attr_lf(result):
assert result == 3
Contributions are very welcome. Tests can be run with pytest
.
Distributed under the terms of the MIT
license, pytest-lazy-fixtures
is free and open source software
If you encounter any problems, please file an issue along with a detailed description.
FAQs
Allows you to use fixtures in @pytest.mark.parametrize.
We found that pytest-lazy-fixtures demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.