commit a0fc5e6f4ef76cd935839f08cf9f3db962d95a99 Author: Arturo Filastò arturo@filasto.net Date: Fri Apr 1 19:52:25 2016 +0200
[hotfix] Ensure the _setUp() method gets called only once for every input --- ooni/nettest.py | 3 +++ ooni/tasks.py | 1 - ooni/templates/httpt.py | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/ooni/nettest.py b/ooni/nettest.py index 848d958..43ae23b 100644 --- a/ooni/nettest.py +++ b/ooni/nettest.py @@ -525,6 +525,7 @@ class NetTest(object): for input in test_class.inputs: measurements = [] test_instance = test_class() + test_instance._setUp() test_instance.summary = self.summary for method in test_methods: log.debug("Running %s %s" % (test_class, method)) @@ -645,6 +646,7 @@ class NetTestCase(object): def _setUp(self): """ This is the internal setup method to be overwritten by templates. + It gets called once for every input. """ self.report = {} self.inputs = None @@ -659,6 +661,7 @@ class NetTestCase(object): def setUp(self): """ Place here your logic to be executed when the test is being setup. + It gets called once every test method + input. """ pass
diff --git a/ooni/tasks.py b/ooni/tasks.py index 3f331a2..bd8cbc9 100644 --- a/ooni/tasks.py +++ b/ooni/tasks.py @@ -110,7 +110,6 @@ class Measurement(TaskWithTimeout): """ self.testInstance = test_instance self.testInstance.input = test_input - self.testInstance._setUp() if not hasattr(self.testInstance, '_start_time'): self.testInstance._start_time = time.time()
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py index 3702e86..2f1136c 100644 --- a/ooni/templates/httpt.py +++ b/ooni/templates/httpt.py @@ -141,7 +141,6 @@ class HTTPTest(NetTestCase): } if failure_string: request_response['failure'] = failure_string - self.report['requests'].append(request_response)
def _processResponseBody(self, response_body, request, response, body_processor): @@ -312,8 +311,7 @@ class HTTPTest(NetTestCase): log.debug("Randomizing user agent") self.randomize_useragent(request)
- if 'requests' not in self.report: - self.report['requests'] = [] + self.report['requests'] = self.report.get('requests', [])
# If we have a request body payload, set the request body to such # content
tor-commits@lists.torproject.org