Skip to content

Instantly share code, notes, and snippets.

@hakib
Last active May 8, 2020 16:43
Show Gist options
  • Select an option

  • Save hakib/a10f1ac7fcce6505865ae6ac7daeb686 to your computer and use it in GitHub Desktop.

Select an option

Save hakib/a10f1ac7fcce6505865ae6ac7daeb686 to your computer and use it in GitHub Desktop.

Revisions

  1. hakib revised this gist Dec 17, 2019. 1 changed file with 40 additions and 4 deletions.
    44 changes: 40 additions & 4 deletions pytest_fixtures_as_parameters.py
    Original file line number Diff line number Diff line change
    @@ -12,16 +12,52 @@ def B():

    # What I can do

    def A_is_one(A):
    def test_A_is_one(A):
    assert A == 1

    def B_is_one(B):
    def test_B_is_one(B):
    assert B == 1



    # What I want to do

    @pytest.mark.parametrize('foo', [A, B])
    def is_one(foo):
    assert foo == 1
    def test_is_one(foo):
    assert foo == 1


    """
    $ pytest test.py
    ==================================================================================== test session starts =====================================================================================
    platform linux -- Python 3.7.5, pytest-5.3.0, py-1.8.0, pluggy-0.13.0
    Django settings: conf.settings (from ini file)
    rootdir: /home/haki/src/ravkav-store/server, inifile: pytest.ini
    plugins: django-3.5.1
    collected 4 items
    test.py ..FF [100%]
    ========================================================================================== FAILURES ==========================================================================================
    _______________________________________________________________________________________ test_is_one[A] _______________________________________________________________________________________
    foo = <function A at 0x7f93f51c9d40>
    @pytest.mark.parametrize('foo', [A, B])
    def test_is_one(foo):
    > assert foo == 1
    E assert <function A at 0x7f93f51c9d40> == 1
    test.py:27: AssertionError
    _______________________________________________________________________________________ test_is_one[B] _______________________________________________________________________________________
    foo = <function B at 0x7f93f51c9e60>
    @pytest.mark.parametrize('foo', [A, B])
    def test_is_one(foo):
    > assert foo == 1
    E assert <function B at 0x7f93f51c9e60> == 1
    test.py:27: AssertionError
    ================================================================================ 2 failed, 2 passed in 0.09s =================================================================================
    """
  2. hakib revised this gist Dec 17, 2019. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions pytest_fixtures_as_parameters.py
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,20 @@ def A():
    def B():
    return 1



    # What I can do

    def A_is_one(A):
    assert A == 1

    def B_is_one(B):
    assert B == 1



    # What I want to do

    @pytest.mark.parametrize('foo', [A, B])
    def is_one(foo):
    assert foo == 1
  3. hakib created this gist Dec 17, 2019.
    13 changes: 13 additions & 0 deletions pytest_fixtures_as_parameters.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    import pytest

    @pytest.fixture
    def A():
    return 1

    @pytest.fixture
    def B():
    return 1

    @pytest.mark.parametrize('foo', [A, B])
    def is_one(foo):
    assert foo == 1