From 2274a6ecbb766f2253d257ab723bf726d650f765 2025-02-14 22:38:14
From: Branko Majic <branko@majic.rs>
Date: 2025-02-14 22:38:14
Subject: [PATCH] MAR-242: Mark some of the HTTP file sharing tests as slow:

- Update develpment instructions to include information on how to run
  individual tests etc.

---

diff --git a/docs/development.rst b/docs/development.rst
index b2f0fd2c3c5591a3a508d28e5eda1c7c904508a0..f05f37182fa3b67519d7eef4fb6a60b67d3d4538 100644
--- a/docs/development.rst
+++ b/docs/development.rst
@@ -172,6 +172,56 @@ In order to run tests for a specific role, perform the following steps:
      molecule test
 
 
+Running role tests during development
+-------------------------------------
+
+During development, as new features are being implemented, it is
+usually necessary to bring up the test machines and have them
+operational for prolonged periods of time while changes are being
+applied and tested.
+
+This usually starts off by bringing up the test machines and applying
+the configuration against them using Ansible::
+
+  workon majic-ansible-roles
+  cd roles/ROLENAME/
+  molecule converge
+
+After the test machines have been brought up and configured, tests can
+be run with (without destroying the test machines themselves)::
+
+  molecule verify
+
+Another scenario is ability to run individual tests for faster
+develpoment iteration. Individual tests can be selected for execution
+by passing options to the underlying test runner (`pytest
+<https://docs.pytest.org/en/stable/>`_) via ``PYTEST_ADDOPTS``
+environment variable.
+
+For example, to run a singular test by its function name, use the
+``-k`` option::
+
+  PYTEST_ADDOPTS="-k test_config_file_content" molecule verify
+
+Tests can also be decorated with markers (``@pytest.mark.*``), which
+can in turn be used to run the matching (marked) subset of tests. For
+example, to execute slow-running tests (decorated with
+``@pytest.mark.slow``), run::
+
+  PYTEST_ADDOPTS="-m slow" molecule verify
+
+To exclude the slow-running tests, use logical expressions (just make
+sure to surround the entire expression with additional quotation
+marks)::
+  
+  PYTEST_ADDOPTS="-m 'not slow'" molecule verify
+
+To determine what tests take a long time to finish, use the
+``--durations`` option::
+
+  PYTEST_ADDOPTS="--durations 0" molecule verify"
+
+
 Running role tests via shell script
 -----------------------------------
 
diff --git a/pytest.ini b/pytest.ini
new file mode 100644
index 0000000000000000000000000000000000000000..42c76b4dac736add2093bfdf01a7411f679b2c4a
--- /dev/null
+++ b/pytest.ini
@@ -0,0 +1,3 @@
+[pytest]
+markers =
+  slow: mark test as slow
\ No newline at end of file
diff --git a/roles/xmpp_server/molecule/default/tests/test_client.py b/roles/xmpp_server/molecule/default/tests/test_client.py
index 66cd9fc98353f956b8924022c41b883cfec17ccc..3c9b84f9e3a17ee500df3a6b3170948023dc80af 100644
--- a/roles/xmpp_server/molecule/default/tests/test_client.py
+++ b/roles/xmpp_server/molecule/default/tests/test_client.py
@@ -151,6 +151,7 @@ def test_http_file_upload(host, server_host, username, password, domain):
     ["mick.doe", "mickpassword", "domain3", "parameters-optional", 20 * 1024 * 1024],
 ])
 @pytest.mark.usefixtures("server_clean_domain_uploads")
+@pytest.mark.slow
 def test_http_file_share_size_limit(host, username, password, domain, file_size_limit):
     """
     Tests the maximum file size for files uploaded via XEP-0363.
@@ -181,6 +182,7 @@ def test_http_file_share_size_limit(host, username, password, domain, file_size_
     ["mick.doe", "mickpassword", "domain3", "parameters-optional", 20 * 1024 * 1024, 70 * 1024 * 1024],
 ])
 @pytest.mark.usefixtures("server_clean_domain_uploads")
+@pytest.mark.slow
 def test_http_file_share_daily_quota(host, username, password, domain, file_size_limit, user_daily_quota):
     """
     Tests the user's daily quota for files uploaded via XEP-0363.