Skip to content

Instantly share code, notes, and snippets.

@hakib
Last active May 8, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hakib/a10f1ac7fcce6505865ae6ac7daeb686 to your computer and use it in GitHub Desktop.
Save hakib/a10f1ac7fcce6505865ae6ac7daeb686 to your computer and use it in GitHub Desktop.
import pytest
@pytest.fixture
def A():
return 1
@pytest.fixture
def B():
return 1
# What I can do
def test_A_is_one(A):
assert A == 1
def test_B_is_one(B):
assert B == 1
# What I want to do
@pytest.mark.parametrize('foo', [A, B])
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 =================================================================================
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment