From dc6671fc4ef5663d7d027478d568e4af62e6686b Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 8 Feb 2020 18:51:54 +0100 Subject: [PATCH] Add an integration tests which generates a key Configuring an online account generates a key, we would like this code-path tested too. So add some functionality to the AccountManager to not use the pre-generated keys. Because this slows down interactively running the tests by hand add an ignored marker which only runs if --ignored is used. This name was chosen because this matches the naming used by rust/cargo #[ignored]. The difference however is that --ignored on cargo *only* runs ignored tests while here it runs *all* tests. To ensure the ignored/slow tests are run on CI we add it as an argument to the tox configuration, which is used by the CI to run the tests. --- python/tests/conftest.py | 29 +++++++++++++++++++++++------ python/tests/test_account.py | 6 ++++++ python/tox.ini | 4 ++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 6296248fa..9310fb726 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -16,9 +16,16 @@ def pytest_addoption(parser): help="a file with >=2 lines where each line " "contains NAME=VALUE config settings for one account" ) + parser.addoption( + "--ignored", action="store_true", + help="Also run tests marked with the ignored marker", + ) def pytest_configure(config): + config.addinivalue_line( + "markers", "ignored: Mark test as bing slow, skipped unless --ignored is used." + ) cfg = config.getoption('--liveconfig') if not cfg: cfg = os.getenv('DCC_PY_LIVECONFIG') @@ -26,6 +33,12 @@ def pytest_configure(config): config.option.liveconfig = cfg +def pytest_runtest_setup(item): + if (list(item.iter_markers(name="ignored")) + and not item.config.getoption("ignored")): + pytest.skip("Ignored tests not requested, use --ignored") + + def pytest_report_header(config, startdir): summary = [] @@ -186,7 +199,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, datadir): pytest.skip("specify DCC_PY_LIVECONFIG or --liveconfig") return session_liveconfig.get(self.live_count) - def get_online_config(self): + def get_online_config(self, pre_generated_key=True): if not session_liveconfig: pytest.skip("specify DCC_PY_LIVECONFIG or --liveconfig") configdict = session_liveconfig.get(self.live_count) @@ -200,19 +213,23 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, datadir): tmpdb = tmpdir.join("livedb%d" % self.live_count) ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count)) - self._preconfigure_key(ac, configdict['addr']) + if pre_generated_key: + self._preconfigure_key(ac, configdict['addr']) ac._evlogger.init_time = self.init_time ac._evlogger.set_timeout(30) return ac, dict(configdict) - def get_online_configuring_account(self, mvbox=False, sentbox=False): - ac, configdict = self.get_online_config() + def get_online_configuring_account(self, mvbox=False, sentbox=False, + pre_generated_key=True): + ac, configdict = self.get_online_config( + pre_generated_key=pre_generated_key) ac.configure(**configdict) ac.start_threads(mvbox=mvbox, sentbox=sentbox) return ac - def get_one_online_account(self): - ac1 = self.get_online_configuring_account() + def get_one_online_account(self, pre_generated_key=True): + ac1 = self.get_online_configuring_account( + pre_generated_key=pre_generated_key) wait_successful_IMAP_SMTP_connection(ac1) wait_configuration_progress(ac1, 1000) return ac1 diff --git a/python/tests/test_account.py b/python/tests/test_account.py index e8536b949..07ffe6b2b 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -417,6 +417,12 @@ class TestOfflineChat: class TestOnlineAccount: + @pytest.mark.ignored + def test_configure_generate_key(self, acfactory): + # A slow test which will generate a new key. + ac = acfactory.get_one_online_account(pre_generated_key=False) + ac.check_is_configured() + def get_chat(self, ac1, ac2, both_created=False): c2 = ac1.create_contact(email=ac2.get_config("addr")) chat = ac1.create_chat_by_contact(c2) diff --git a/python/tox.ini b/python/tox.ini index b80c55891..5ad7caa7f 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -7,7 +7,7 @@ envlist = [testenv] commands = - pytest -n6 --reruns 2 --reruns-delay 5 -v -rsXx {posargs:tests} + pytest -n6 --reruns 2 --reruns-delay 5 -v -rsXx --ignored {posargs:tests} python tests/package_wheels.py {toxworkdir}/wheelhouse passenv = TRAVIS @@ -65,7 +65,7 @@ commands = [pytest] -addopts = -v -ra +addopts = -v -ra --strict-markers python_files = tests/test_*.py norecursedirs = .tox xfail_strict=true