From a7509988af093922e9613593f84bb5eea85f8f08 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sun, 20 Jan 2019 20:02:31 +0100 Subject: [PATCH] Rev3802, Fix pytest warnings --- .../Test/TestBootstrapper.py | 2 +- src/Config.py | 2 +- src/Test/TestTor.py | 2 +- src/Test/TestUpnpPunch.py | 4 ++-- src/Test/conftest.py | 19 ++++++++++++------- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/disabled-Bootstrapper/Test/TestBootstrapper.py b/plugins/disabled-Bootstrapper/Test/TestBootstrapper.py index fabec8c3..d99f8ea7 100644 --- a/plugins/disabled-Bootstrapper/Test/TestBootstrapper.py +++ b/plugins/disabled-Bootstrapper/Test/TestBootstrapper.py @@ -185,7 +185,7 @@ class TestBootstrapper: assert len(site.peers) == 2 assert "bka4ht2bzxchy44r.onion:1234" in site.peers - @pytest.mark.skipif(not pytest.config.getvalue("slow"), reason="--slow not requested (takes around ~ 1min)") + @pytest.mark.slow def testAnnounce(self, file_server, tor_manager): file_server.tor_manager = tor_manager hash1 = hashlib.sha256("1Nekos4fiBqfcazyG1bAxdBT5oBvA76Z").digest() diff --git a/src/Config.py b/src/Config.py index 927a853b..ce53c664 100644 --- a/src/Config.py +++ b/src/Config.py @@ -13,7 +13,7 @@ class Config(object): def __init__(self, argv): self.version = "0.6.4" - self.rev = 3801 + self.rev = 3802 self.argv = argv self.action = None self.pending_changes = {} diff --git a/src/Test/TestTor.py b/src/Test/TestTor.py index 63339ea7..d40fe0f9 100644 --- a/src/Test/TestTor.py +++ b/src/Test/TestTor.py @@ -49,7 +49,7 @@ class TestTor: # Delete tor_manager.delOnion(address) - @pytest.mark.skipif(not pytest.config.getvalue("slow"), reason="--slow not requested (takes around ~ 1min)") + @pytest.mark.slow def testConnection(self, tor_manager, file_server, site, site_temp): file_server.tor_manager.start_onions = True address = file_server.tor_manager.getOnion(site.address) diff --git a/src/Test/TestUpnpPunch.py b/src/Test/TestUpnpPunch.py index f77d7f8d..18338bb9 100644 --- a/src/Test/TestUpnpPunch.py +++ b/src/Test/TestUpnpPunch.py @@ -128,7 +128,7 @@ class TestUpnpPunch(object): rsp = httplib_response(status=500) with pytest.raises(upnp.IGDError) as exc: upnp._parse_for_errors(rsp) - assert 'Unable to parse' in exc.value.message + assert 'Unable to parse' in str(exc) def test_parse_for_errors_error(self, httplib_response): soap_error = ('' @@ -138,7 +138,7 @@ class TestUpnpPunch(object): rsp = httplib_response(status=500, body=soap_error) with pytest.raises(upnp.IGDError) as exc: upnp._parse_for_errors(rsp) - assert 'SOAP request error' in exc.value.message + assert 'SOAP request error' in str(exc) def test_parse_for_errors_good_rsp(self, httplib_response): rsp = httplib_response(status=200) diff --git a/src/Test/conftest.py b/src/Test/conftest.py index ae8b0fd9..76994786 100644 --- a/src/Test/conftest.py +++ b/src/Test/conftest.py @@ -18,6 +18,15 @@ monkey.patch_all(thread=False, subprocess=False) def pytest_addoption(parser): parser.addoption("--slow", action='store_true', default=False, help="Also run slow tests") +def pytest_collection_modifyitems(config, items): + if config.getoption("--slow"): + # --runslow given in cli: do not skip slow tests + return + skip_slow = pytest.mark.skip(reason="need --slow option to run") + for item in items: + if "slow" in item.keywords: + item.add_marker(skip_slow) + # Config if sys.platform == "win32": CHROMEDRIVER_PATH = "tools/chrome/chromedriver.exe" @@ -90,10 +99,6 @@ from Content import ContentDb from util import RateLimit from Db import Db -# SiteManager.site_manager.load = mock.MagicMock(return_value=True) # Don't try to load from sites.json -# SiteManager.site_manager.save = mock.MagicMock(return_value=True) # Don't try to load from sites.json - - @pytest.fixture(scope="session") def resetSettings(request): open("%s/sites.json" % config.data_dir, "w").write("{}") @@ -204,7 +209,7 @@ def browser(request): options.add_argument("--headless") options.add_argument("--window-size=1920x1080") options.add_argument("--log-level=1") - browser = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, service_log_path=os.path.devnull, chrome_options=options) + browser = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, service_log_path=os.path.devnull, options=options) def quit(): browser.quit() @@ -226,9 +231,9 @@ def site_url(): @pytest.fixture(params=['ipv4', 'ipv6']) def file_server(request): if request.param == "ipv4": - return request.getfuncargvalue("file_server4") + return request.getfixturevalue("file_server4") else: - return request.getfuncargvalue("file_server6") + return request.getfixturevalue("file_server6") @pytest.fixture