[pytest-dev] Issue mixing skipif and parametrize
Lele Gaifax
lele at metapensiero.it
Mon Mar 13 09:36:56 EDT 2017
Hi all,
I have a parametrized test function that loads a set of cases from the
filesystem, something like
@pytest.mark.parametrize('py_code',
load_tests_from_directory('some_directory'))
def test_foo(py_code):
assert some_property(py_code)
The `load_tests_from_directory()` loads Python snippets from the given
directory and basically returns their code objects (that is, the result of
`compile(snippet, 'exec')`).
Now I have a new set of snippets that are Python 3.6 only (they use
f-strings), and I would like to execute those tests only under Python 3.6+.
I tried the obvious, that is
@pytest.mark.skipif(sys.version_info < (3,6))
@pytest.mark.parametrize('py_code',
load_tests_from_directory('py36_specific_dir'))
def test_foo_py36_only(py_code):
assert some_property(py_code)
but unfortunately that does not work, because the parametrization happens also
when the skipif condition is met, and thus the compile() call crash.
Is there a better alternative to recode the above like
@pytest.mark.skipif(sys.version_info < (3,6))
def test_foo_py36_only(py_code):
for py_code in load_tests_from_directory('py36_specific_dir'):
assert some_property(py_code)
?
Thanks in advance for any hint,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it | -- Fortunato Depero, 1929.
More information about the pytest-dev
mailing list