Skip to content

Commit

Permalink
Rev3802, Fix pytest warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Jan 20, 2019
1 parent f58f738 commit a750998
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion plugins/disabled-Bootstrapper/Test/TestBootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def testRequestPeers(self, file_server, site, bootstrapper_db, tor_manager):
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()
Expand Down
2 changes: 1 addition & 1 deletion src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion src/Test/TestTor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def testSignOnion(self, tor_manager):
# 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)
Expand Down
4 changes: 2 additions & 2 deletions src/Test/TestUpnpPunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_parse_for_errors_bad_rsp(self, httplib_response):
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 = ('<document>'
Expand All @@ -138,7 +138,7 @@ def test_parse_for_errors_error(self, httplib_response):
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)
Expand Down
19 changes: 12 additions & 7 deletions src/Test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
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"
Expand Down Expand Up @@ -90,10 +99,6 @@ def filter(self, record):
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("{}")
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit a750998

Please sign in to comment.