Repository: freedomofpress/securedrop

Issue:
Update pytest-*, molecule, testinfra dependencies
## Description


Currently we are using 3 years old versions of `pytest`, `pytest-xdist`, `pluggy`, `testinfra`, `molecule`.  We have to update these dependencies up to
the latest version where they support both Python3.5  and 3.8 (for `xenial` and `focal`).





Discussion:

Resolving patch:
diff --git a/molecule/testinfra/conftest.py b/molecule/testinfra/conftest.py
--- a/molecule/testinfra/conftest.py
+++ b/molecule/testinfra/conftest.py
@@ -9,6 +9,7 @@
 import io
 import os
 import yaml
+import testutils
 
 # The config tests target staging by default. It's possible to override
 # for e.g. prod, but the associated vars files are not yet ported.
@@ -52,5 +53,13 @@ def lookup_molecule_info():
     return molecule_instance_config
 
 
-def pytest_namespace():
-    return securedrop_import_testinfra_vars(target_host, with_header=True)
+class Myvalues:
+    def __init__(self):
+        pass
+
+
+value = securedrop_import_testinfra_vars(target_host)
+res = Myvalues()
+for key, value in value.items():
+    setattr(res, key, value)
+testutils.securedrop_test_vars = res
diff --git a/molecule/testinfra/testutils.py b/molecule/testinfra/testutils.py
new file mode 100644
--- /dev/null
+++ b/molecule/testinfra/testutils.py
@@ -0,0 +1 @@
+securedrop_test_vars = {}


Test patch:
diff --git a/molecule/builder-xenial/tests/conftest.py b/molecule/builder-xenial/tests/conftest.py
--- a/molecule/builder-xenial/tests/conftest.py
+++ b/molecule/builder-xenial/tests/conftest.py
@@ -1,22 +1,19 @@
 """
-Import variables from vars.yml and inject into pytest namespace
+Import variables from vars.yml and inject into testutils namespace
 """
 
 import os
 import io
 import yaml
+import testutils
 
 
-def pytest_namespace():
-    """ Return dict of vars imported as 'securedrop_test_vars' into pytest
-        global namespace
-    """
-    filepath = os.path.join(os.path.dirname(__file__), "vars.yml")
-    with io.open(filepath, 'r') as f:
-        securedrop_test_vars = yaml.safe_load(f)
+filepath = os.path.join(os.path.dirname(__file__), "vars.yml")
+with io.open(filepath, 'r') as f:
+    securedrop_test_vars = yaml.safe_load(f)
 
-    # Tack on target OS for use in tests
-    securedrop_target_platform = os.environ.get("SECUREDROP_TARGET_PLATFORM")
-    securedrop_test_vars["securedrop_target_platform"] = securedrop_target_platform
-    # Wrapping the return value to accommodate for pytest namespacing
-    return dict(securedrop_test_vars=securedrop_test_vars)
+# Tack on target OS for use in tests
+securedrop_target_platform = os.environ.get("SECUREDROP_TARGET_PLATFORM")
+securedrop_test_vars["securedrop_target_platform"] = securedrop_target_platform
+
+testutils.securedrop_test_vars = testutils.inject_vars(securedrop_test_vars)
diff --git a/molecule/builder-xenial/tests/test_securedrop_deb_package.py b/molecule/builder-xenial/tests/test_securedrop_deb_package.py
--- a/molecule/builder-xenial/tests/test_securedrop_deb_package.py
+++ b/molecule/builder-xenial/tests/test_securedrop_deb_package.py
@@ -2,13 +2,14 @@
 import os
 import re
 import tempfile
+import testutils
 
 
 SECUREDROP_TARGET_PLATFORM = os.environ.get("SECUREDROP_TARGET_PLATFORM")
 testinfra_hosts = [
         "docker://{}-sd-dpkg-verification".format(SECUREDROP_TARGET_PLATFORM)
 ]
-securedrop_test_vars = pytest.securedrop_test_vars
+securedrop_test_vars = testutils.securedrop_test_vars
 
 
 def extract_package_name_from_filepath(filepath):
diff --git a/molecule/builder-xenial/tests/testutils.py b/molecule/builder-xenial/tests/testutils.py
new file mode 100644
--- /dev/null
+++ b/molecule/builder-xenial/tests/testutils.py
@@ -0,0 +1,13 @@
+class Myvalues:
+    def __init__(self):
+        pass
+
+
+securedrop_test_vars = Myvalues()
+
+
+def inject_vars(value):
+    res = Myvalues()
+    for key, value in value.items():
+        setattr(res, key, value)
+    return res
diff --git a/molecule/testinfra/app-code/test_haveged.py b/molecule/testinfra/app-code/test_haveged.py
--- a/molecule/testinfra/app-code/test_haveged.py
+++ b/molecule/testinfra/app-code/test_haveged.py
@@ -1,6 +1,6 @@
-import pytest
+import testutils
 
-sdvars = pytest.securedrop_test_vars
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 
diff --git a/molecule/testinfra/app-code/test_securedrop_app_code.py b/molecule/testinfra/app-code/test_securedrop_app_code.py
--- a/molecule/testinfra/app-code/test_securedrop_app_code.py
+++ b/molecule/testinfra/app-code/test_securedrop_app_code.py
@@ -1,7 +1,9 @@
 import pytest
 
 
-securedrop_test_vars = pytest.securedrop_test_vars
+import testutils
+
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.app_hostname]
 python_version = securedrop_test_vars.python_version
 
diff --git a/molecule/testinfra/app-code/test_securedrop_rqrequeue.py b/molecule/testinfra/app-code/test_securedrop_rqrequeue.py
--- a/molecule/testinfra/app-code/test_securedrop_rqrequeue.py
+++ b/molecule/testinfra/app-code/test_securedrop_rqrequeue.py
@@ -1,14 +1,13 @@
-import pytest
+import testutils
 
-sdvars = pytest.securedrop_test_vars
-testinfra_hosts = [sdvars.app_hostname]
+securedrop_test_vars = testutils.securedrop_test_vars
+testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 
 def test_securedrop_rqrequeue_service(host):
     """
     Verify configuration of securedrop_rqrequeue systemd service.
     """
-    securedrop_test_vars = pytest.securedrop_test_vars
     service_file = "/lib/systemd/system/securedrop_rqrequeue.service"
     expected_content = "\n".join([
         "[Unit]",
diff --git a/molecule/testinfra/app-code/test_securedrop_rqworker.py b/molecule/testinfra/app-code/test_securedrop_rqworker.py
--- a/molecule/testinfra/app-code/test_securedrop_rqworker.py
+++ b/molecule/testinfra/app-code/test_securedrop_rqworker.py
@@ -1,6 +1,6 @@
-import pytest
+import testutils
 
-sdvars = pytest.securedrop_test_vars
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 
@@ -8,7 +8,7 @@ def test_securedrop_rqworker_service(host):
     """
     Verify configuration of securedrop_rqworker systemd service.
     """
-    securedrop_test_vars = pytest.securedrop_test_vars
+    securedrop_test_vars = sdvars
     service_file = "/lib/systemd/system/securedrop_rqworker.service"
 
     expected_content = "\n".join([
diff --git a/molecule/testinfra/app-code/test_securedrop_shredder_configuration.py b/molecule/testinfra/app-code/test_securedrop_shredder_configuration.py
--- a/molecule/testinfra/app-code/test_securedrop_shredder_configuration.py
+++ b/molecule/testinfra/app-code/test_securedrop_shredder_configuration.py
@@ -1,6 +1,6 @@
-import pytest
+import testutils
 
-sdvars = pytest.securedrop_test_vars
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 
@@ -8,7 +8,7 @@ def test_securedrop_shredder_service(host):
     """
     Verify configuration of securedrop_shredder systemd service.
     """
-    securedrop_test_vars = pytest.securedrop_test_vars
+    securedrop_test_vars = sdvars
     service_file = "/lib/systemd/system/securedrop_shredder.service"
     expected_content = "\n".join([
         "[Unit]",
diff --git a/molecule/testinfra/app-code/test_securedrop_source_deleter_configuration.py b/molecule/testinfra/app-code/test_securedrop_source_deleter_configuration.py
--- a/molecule/testinfra/app-code/test_securedrop_source_deleter_configuration.py
+++ b/molecule/testinfra/app-code/test_securedrop_source_deleter_configuration.py
@@ -1,14 +1,13 @@
-import pytest
+import testutils
 
-sdvars = pytest.securedrop_test_vars
-testinfra_hosts = [sdvars.app_hostname]
+securedrop_test_vars = testutils.securedrop_test_vars
+testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 
 def test_securedrop_source_deleter_service(host):
     """
     Verify configuration of securedrop_source_deleter systemd service.
     """
-    securedrop_test_vars = pytest.securedrop_test_vars
     service_file = "/lib/systemd/system/securedrop_source_deleter.service"
     expected_content = "\n".join([
         "[Unit]",
diff --git a/molecule/testinfra/app/apache/test_apache_journalist_interface.py b/molecule/testinfra/app/apache/test_apache_journalist_interface.py
--- a/molecule/testinfra/app/apache/test_apache_journalist_interface.py
+++ b/molecule/testinfra/app/apache/test_apache_journalist_interface.py
@@ -1,8 +1,9 @@
 import pytest
 import re
 
+import testutils
 
-securedrop_test_vars = pytest.securedrop_test_vars
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 # Setting once so it can be reused in multiple tests.
diff --git a/molecule/testinfra/app/apache/test_apache_service.py b/molecule/testinfra/app/apache/test_apache_service.py
--- a/molecule/testinfra/app/apache/test_apache_service.py
+++ b/molecule/testinfra/app/apache/test_apache_service.py
@@ -1,7 +1,8 @@
 import pytest
 
+import testutils
 
-securedrop_test_vars = pytest.securedrop_test_vars
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/apache/test_apache_source_interface.py b/molecule/testinfra/app/apache/test_apache_source_interface.py
--- a/molecule/testinfra/app/apache/test_apache_source_interface.py
+++ b/molecule/testinfra/app/apache/test_apache_source_interface.py
@@ -1,7 +1,9 @@
 import pytest
 import re
 
-securedrop_test_vars = pytest.securedrop_test_vars
+import testutils
+
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/apache/test_apache_system_config.py b/molecule/testinfra/app/apache/test_apache_system_config.py
--- a/molecule/testinfra/app/apache/test_apache_system_config.py
+++ b/molecule/testinfra/app/apache/test_apache_system_config.py
@@ -1,7 +1,9 @@
 import pytest
 import re
 
-securedrop_test_vars = pytest.securedrop_test_vars
+import testutils
+
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/test_app_network.py b/molecule/testinfra/app/test_app_network.py
--- a/molecule/testinfra/app/test_app_network.py
+++ b/molecule/testinfra/app/test_app_network.py
@@ -5,7 +5,9 @@
 from jinja2 import Template
 
 
-securedrop_test_vars = pytest.securedrop_test_vars
+import testutils
+
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/test_apparmor.py b/molecule/testinfra/app/test_apparmor.py
--- a/molecule/testinfra/app/test_apparmor.py
+++ b/molecule/testinfra/app/test_apparmor.py
@@ -1,7 +1,9 @@
 import pytest
 
 
-sdvars = pytest.securedrop_test_vars
+import testutils
+
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/test_appenv.py b/molecule/testinfra/app/test_appenv.py
--- a/molecule/testinfra/app/test_appenv.py
+++ b/molecule/testinfra/app/test_appenv.py
@@ -1,7 +1,9 @@
 import os.path
 import pytest
 
-sdvars = pytest.securedrop_test_vars
+import testutils
+
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/test_ossec_agent.py b/molecule/testinfra/app/test_ossec_agent.py
--- a/molecule/testinfra/app/test_ossec_agent.py
+++ b/molecule/testinfra/app/test_ossec_agent.py
@@ -2,7 +2,9 @@
 import re
 import pytest
 
-sdvars = pytest.securedrop_test_vars
+import testutils
+
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/test_paxctld.py b/molecule/testinfra/app/test_paxctld.py
--- a/molecule/testinfra/app/test_paxctld.py
+++ b/molecule/testinfra/app/test_paxctld.py
@@ -1,8 +1,7 @@
-import pytest
 import re
+import testutils
 
-
-securedrop_test_vars = pytest.securedrop_test_vars
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/test_tor_config.py b/molecule/testinfra/app/test_tor_config.py
--- a/molecule/testinfra/app/test_tor_config.py
+++ b/molecule/testinfra/app/test_tor_config.py
@@ -1,7 +1,9 @@
 import pytest
 import re
 
-sdvars = pytest.securedrop_test_vars
+import testutils
+
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 
diff --git a/molecule/testinfra/app/test_tor_hidden_services.py b/molecule/testinfra/app/test_tor_hidden_services.py
--- a/molecule/testinfra/app/test_tor_hidden_services.py
+++ b/molecule/testinfra/app/test_tor_hidden_services.py
@@ -1,8 +1,9 @@
 import pytest
 import re
 
+import testutils
 
-sdvars = pytest.securedrop_test_vars
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname]
 
 # Prod Tor services may have unexpected configs
diff --git a/molecule/testinfra/common/test_cron_apt.py b/molecule/testinfra/common/test_cron_apt.py
--- a/molecule/testinfra/common/test_cron_apt.py
+++ b/molecule/testinfra/common/test_cron_apt.py
@@ -1,8 +1,9 @@
 import pytest
 import re
 
+import testutils
 
-test_vars = pytest.securedrop_test_vars
+test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [test_vars.app_hostname, test_vars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/common/test_fpf_apt_repo.py b/molecule/testinfra/common/test_fpf_apt_repo.py
--- a/molecule/testinfra/common/test_fpf_apt_repo.py
+++ b/molecule/testinfra/common/test_fpf_apt_repo.py
@@ -2,7 +2,9 @@
 import re
 
 
-test_vars = pytest.securedrop_test_vars
+import testutils
+
+test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [test_vars.app_hostname, test_vars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/common/test_grsecurity.py b/molecule/testinfra/common/test_grsecurity.py
--- a/molecule/testinfra/common/test_grsecurity.py
+++ b/molecule/testinfra/common/test_grsecurity.py
@@ -1,8 +1,9 @@
 import pytest
 import re
 
+import testutils
 
-sdvars = pytest.securedrop_test_vars
+sdvars = testutils.securedrop_test_vars
 KERNEL_VERSION = sdvars.grsec_version
 testinfra_hosts = [sdvars.app_hostname, sdvars.monitor_hostname]
 
diff --git a/molecule/testinfra/common/test_ip6tables.py b/molecule/testinfra/common/test_ip6tables.py
--- a/molecule/testinfra/common/test_ip6tables.py
+++ b/molecule/testinfra/common/test_ip6tables.py
@@ -1,6 +1,6 @@
-import pytest
+import testutils
 
-test_vars = pytest.securedrop_test_vars
+test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [test_vars.app_hostname, test_vars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/common/test_platform.py b/molecule/testinfra/common/test_platform.py
--- a/molecule/testinfra/common/test_platform.py
+++ b/molecule/testinfra/common/test_platform.py
@@ -1,6 +1,6 @@
-import pytest
+import testutils
 
-test_vars = pytest.securedrop_test_vars
+test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [test_vars.app_hostname, test_vars.monitor_hostname]
 
 # We expect Ubuntu Xenial
diff --git a/molecule/testinfra/common/test_release_upgrades.py b/molecule/testinfra/common/test_release_upgrades.py
--- a/molecule/testinfra/common/test_release_upgrades.py
+++ b/molecule/testinfra/common/test_release_upgrades.py
@@ -1,7 +1,6 @@
-import pytest
+import testutils
 
-
-test_vars = pytest.securedrop_test_vars
+test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [test_vars.app_hostname, test_vars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/common/test_system_hardening.py b/molecule/testinfra/common/test_system_hardening.py
--- a/molecule/testinfra/common/test_system_hardening.py
+++ b/molecule/testinfra/common/test_system_hardening.py
@@ -1,7 +1,9 @@
 import pytest
 import re
 
-sdvars = pytest.securedrop_test_vars
+import testutils
+
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname, sdvars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/common/test_tor_mirror.py b/molecule/testinfra/common/test_tor_mirror.py
--- a/molecule/testinfra/common/test_tor_mirror.py
+++ b/molecule/testinfra/common/test_tor_mirror.py
@@ -1,6 +1,8 @@
 import pytest
 
-test_vars = pytest.securedrop_test_vars
+import testutils
+
+test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [test_vars.app_hostname, test_vars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/common/test_user_config.py b/molecule/testinfra/common/test_user_config.py
--- a/molecule/testinfra/common/test_user_config.py
+++ b/molecule/testinfra/common/test_user_config.py
@@ -3,7 +3,9 @@
 import pytest
 
 
-sdvars = pytest.securedrop_test_vars
+import testutils
+
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.app_hostname, sdvars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/mon/test_mon_network.py b/molecule/testinfra/mon/test_mon_network.py
--- a/molecule/testinfra/mon/test_mon_network.py
+++ b/molecule/testinfra/mon/test_mon_network.py
@@ -4,8 +4,9 @@
 import pytest
 from jinja2 import Template
 
+import testutils
 
-securedrop_test_vars = pytest.securedrop_test_vars
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/mon/test_ossec_ruleset.py b/molecule/testinfra/mon/test_ossec_ruleset.py
--- a/molecule/testinfra/mon/test_ossec_ruleset.py
+++ b/molecule/testinfra/mon/test_ossec_ruleset.py
@@ -1,7 +1,9 @@
 import pytest
 import re
 
-sdvars = pytest.securedrop_test_vars
+import testutils
+
+sdvars = testutils.securedrop_test_vars
 testinfra_hosts = [sdvars.monitor_hostname]
 alert_level_regex = re.compile(r"Level: '(\d+)'")
 rule_id_regex = re.compile(r"Rule id: '(\d+)'")
diff --git a/molecule/testinfra/mon/test_ossec_server.py b/molecule/testinfra/mon/test_ossec_server.py
--- a/molecule/testinfra/mon/test_ossec_server.py
+++ b/molecule/testinfra/mon/test_ossec_server.py
@@ -1,8 +1,9 @@
 import os
 import pytest
 
+import testutils
 
-securedrop_test_vars = pytest.securedrop_test_vars
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.monitor_hostname]
 
 
diff --git a/molecule/testinfra/mon/test_postfix.py b/molecule/testinfra/mon/test_postfix.py
--- a/molecule/testinfra/mon/test_postfix.py
+++ b/molecule/testinfra/mon/test_postfix.py
@@ -1,8 +1,9 @@
 import re
 import pytest
 
+import testutils
 
-securedrop_test_vars = pytest.securedrop_test_vars
+securedrop_test_vars = testutils.securedrop_test_vars
 testinfra_hosts = [securedrop_test_vars.monitor_hostname]