From 7ac8a88a05f3a316344af951f97181d57a26915c Mon Sep 17 00:00:00 2001 From: Raphael Pierzina Date: Wed, 30 Sep 2015 19:25:57 +0200 Subject: [PATCH 1/3] Remove pytest_runtest_setup from conftest.py --- doc/en/example/simple.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst index f75ae4ab2..03471b917 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -131,10 +131,6 @@ line option to control skipping of ``slow`` marked tests:: parser.addoption("--runslow", action="store_true", help="run slow tests") - def pytest_runtest_setup(item): - if 'slow' in item.keywords and not item.config.getoption("--runslow"): - pytest.skip("need --runslow option to run") - We can now write a test module like this:: # content of test_module.py From a10da0e5401dc51cda10ede3095d2958c7720196 Mon Sep 17 00:00:00 2001 From: Raphael Pierzina Date: Wed, 30 Sep 2015 19:41:47 +0200 Subject: [PATCH 2/3] Implement skipif marker for slow test based on pytest.config --- doc/en/example/simple.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst index 03471b917..963b561ac 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -136,12 +136,14 @@ We can now write a test module like this:: # content of test_module.py import pytest - slow = pytest.mark.slow def test_func_fast(): pass - @slow + @pytest.mark.skipif( + not pytest.config.getoption("--runslow"), + reason="need --runslow option to run" + ) def test_func_slow(): pass From 4829eac1e1da64a12b00676b61d762b15f6096d0 Mon Sep 17 00:00:00 2001 From: Raphael Pierzina Date: Wed, 30 Sep 2015 21:53:34 +0200 Subject: [PATCH 3/3] Use a variable for the skipif marker as suggested by @nicoddemus --- doc/en/example/simple.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst index 963b561ac..83fbae121 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -137,13 +137,18 @@ We can now write a test module like this:: import pytest - def test_func_fast(): - pass - @pytest.mark.skipif( + slow = pytest.mark.skipif( not pytest.config.getoption("--runslow"), reason="need --runslow option to run" ) + + + def test_func_fast(): + pass + + + @slow def test_func_slow(): pass