From dea8c293510626181907d802336bedfd78585b4e Mon Sep 17 00:00:00 2001 From: "Christopher K. Hoadley" Date: Sun, 3 Feb 2019 11:14:45 -0600 Subject: [PATCH] Change tests so that all sites that share a common username are executed in parallel. Just the little bit of extra processing halves the time taken for the tests (~15s verus ~34s). This will only get worse as the test coverage improves... --- tests/base.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/base.py b/tests/base.py index e17d8c8d..e3b18970 100644 --- a/tests/base.py +++ b/tests/base.py @@ -128,6 +128,10 @@ class SherlockBaseTest(unittest.TestCase): existence state. """ + #Dictionary of sites that should be tested for having a username. + #This will allow us to test sites with a common username in parallel. + sites_by_username = {} + for site, site_data in self.site_data_all.items(): if ( (site_data["errorType"] != detect_type) or @@ -143,12 +147,22 @@ class SherlockBaseTest(unittest.TestCase): # Figure out which type of user if exist_check: - username_list = [site_data.get("username_claimed")] + username = site_data.get("username_claimed") + else: + username = site_data.get("username_unclaimed") + + # Add this site to the list of sites corresponding to this + # username. + if username in sites_by_username: + sites_by_username[username].append(site) else: - username_list = [site_data.get("username_unclaimed")] - self.username_check(username_list, - [site], - exist_check=exist_check - ) + sites_by_username[username] = [site] + + # Check on the username availability against all of the sites. + for username, site_list in sites_by_username.items(): + self.username_check([username], + site_list, + exist_check=exist_check + ) return