#3803 Drop support for workarounds that were required for old pytest versions
Opened 2 months ago by jhrozek. Modified 2 months ago

SSSD up to 2.0 had to support RHEL-6 with all the old package versions. In the case of pytest it meant we had to do some workarounds like:
- not being able to use pytest.mark.skipif to skip test if a feature is not available
- not being able to use parametrized fixtures to e.g. run the same KCM tests with different back ends just based on a parameter passed through the fixture

Since 2.0 will drop RHEL-6 support, we can get rid of these hacks.


In the case of pytest it meant we had to do some workarounds like:
- not being able to use pytest.mark.skipif to skip test if a feature is not available

That is available since pytest 2.0 and thus also on el6.
But you need to decorate each test e.g.

diff --git a/src/tests/intg/test_kcm.py b/src/tests/intg/test_kcm.py
index 5bacc6f..1e5600a 100644
--- a/src/tests/intg/test_kcm.py
+++ b/src/tests/intg/test_kcm.py
@@ -34,6 +34,11 @@ from secrets import SecretsLocalClient

 MAX_SECRETS = 10

+have_kcm = pytest.mark.skipif(not os.access(os.path.join(config.LIBEXEC_PATH, "sssd",   
+                                                         "sssd_kcm"), 
+                                            os.X_OK),
+                              reason="No KCM responder, skipping")
+

 class KcmTestEnv(object):
     def __init__(self, k5kdc, k5util):
@@ -79,10 +84,6 @@ def create_sssd_kcm_fixture(sock_path, request):
         raise Exception("failed to regenerate confdb")

     resp_path = os.path.join(config.LIBEXEC_PATH, "sssd", "sssd_kcm")
-    if not os.access(resp_path, os.X_OK):
-        # It would be cleaner to use pytest.mark.skipif on the package level
-        # but upstream insists on supporting RHEL-6..
-        pytest.skip("No KCM responder, skipping")

     kcm_pid = os.fork()
     assert kcm_pid >= 0
@@ -203,11 +204,16 @@ def kcm_init_list_destroy(testenv):
     assert nprincs == 0


+@have_kcm
 def test_kcm_mem_init_list_destroy(setup_for_kcm_mem):
     testenv = setup_for_kcm_mem
     kcm_init_list_destroy(testenv)


+@pytest.mark.skipif(not os.access(os.path.join(config.LIBEXEC_PATH, "sssd",   
+                                               "sssd_kcm"), 
+                                  os.X_OK),
+                    reason="No KCM responder, skipping")
 def test_kcm_sec_init_list_destroy(setup_for_kcm_sec,
                                    setup_secrets):
     testenv = setup_for_kcm_sec

//snip
  • not being able to use parametrized fixtures to e.g. run the same KCM tests with different back ends just based on a parameter passed through the fixture

parametrized tests works as well I tried 1st one from
https://docs.pytest.org/en/latest/parametrize.html

sh-4.1$ cat test_expectation.py
# content of test_expectation.py
import pytest
@pytest.mark.parametrize("test_input,expected", [
    ("3+5", 8),
    ("2+4", 6),
    ("6*9", 42),
])  
def test_eval(test_input, expected):
    assert eval(test_input) == expected
sh-4.1$ py.test test_expectation.py
============================= test session starts ==============================
platform linux2 -- Python 2.6.6 -- pytest-2.4.2
collected 3 items 

test_expectation.py ..F

=================================== FAILURES ===================================
______________________________ test_eval[6*9-42] _______________________________

test_input = '6*9', expected = 42

    @pytest.mark.parametrize("test_input,expected", [
        ("3+5", 8),
        ("2+4", 6),
        ("6*9", 42),
    ])
    def test_eval(test_input, expected):
>       assert eval(test_input) == expected
E       assert 54 == 42
E        +  where 54 = eval('6*9')

test_expectation.py:9: AssertionError
====================== 1 failed, 2 passed in 0.02 seconds ======================

Just @pytest.param does not work But it does not work also with pytes-2.7.0 which is on el7

Login to comment on this ticket.

Metadata