pytest-lazy-fixture icon indicating copy to clipboard operation
pytest-lazy-fixture copied to clipboard

fix issue #24: LazyFixture only resolved when used directly, ...

Open artsiomkaltovich opened this issue 4 years ago • 8 comments

Hello the PR has following motivation:

  1. Fix for https://github.com/TvoroG/pytest-lazy-fixture/issues/24.

Usage:

    import pytest
    
    @pytest.fixture(params=[
        dict(one=1, two=pytest.lazy_fixture('two')),
        dict(one=pytest.lazy_fixture('one'), two=2),
        dict(one=pytest.lazy_fixture('one'), two=pytest.lazy_fixture('two'))
    ])
    def some(request):
        return request.param
    
    @pytest.fixture
    def one():
        return 1
    
    @pytest.fixture
    def two():
        return 2
    
    def test_func(some):
        assert some == dict(one=1, two=2)

More samples can be found in tests.

  1. Extends current syntax for creating list of fixtures:

    pytest.lazy_fixture(['one', 'two'])

with more possibilities:

 pytest.lazy_fixture('one', 'two')  # will create a tuple
 pytest.lazy_fixture(one='one', two='two')  # will create a dict

Do not hesitate to express your opinion about code and syntax.

Regards, Artyom.

P.S. Как там Казань? Почему творог, а не эчпочмак? :)

artsiomkaltovich avatar Oct 02 '19 10:10 artsiomkaltovich

Hey! Thanks for pr!

Как там Казань?

Все норм, только чутка холодновато сейчас :)

TvoroG avatar Oct 02 '19 17:10 TvoroG

Hello @TvoroG.

Have you had a chance to review the code? Do you have any comments? Will the PR be merged?

Regards, Artyom.

artsiomkaltovich avatar Oct 03 '19 13:10 artsiomkaltovich

Hey!

Have you had a chance to review the code?

Forget to send comments :)

TvoroG avatar Oct 03 '19 13:10 TvoroG

Hi @TvoroG and @ArtyomKaltovich,

Is this PR in the works? If not, I'm willing to take over, I really need this kind of functionality.

elilutsky avatar Apr 05 '20 08:04 elilutsky

Hello @elilutsky.

Looking up every collection drammatically slow down the performance of the tests, I've tried to do it optional, but failed :)

You can try it.

artsiomkaltovich avatar Apr 07 '20 16:04 artsiomkaltovich

What if you could somehow explicitly mark a dictionary, list, ... that it needs to be searched for nested things?

E.g.:

LazyFixtureList(['a', 'b', lazy_fixture('c'), 'd'])

And maybe there a way of adding some optional syntactic sugar, like this

from pytest_lazyfixture import Lazy
Lazy+['a', 'b', lazy_fixture('c'), 'd']
Lazy+{'x': 1, 'y': lazy_fixture('z')}

YannickJadoul avatar Apr 07 '20 23:04 YannickJadoul