2

I've been having this problem when I run tests and I can't narrow it down because I'm a little new to this and I can't seem to figure it out or find help elsewhere. After the tests execute, if there is an error, I usually get this output:

Traceback (most recent call last):
    File "./src/automated_tests/tests_launcher.py", line 215, in <module>
        pprint(result.jsonify())
    File "./src/automated_tests/tests_launcher.py", line 110, in jsonify
        json_out = self.json_append(t, ERROR, json_out, k)
    File "./src/automated_tests/tests_launcher.py", line 93, in json_append
        {LOGS: logs, STATUS: result, TITLE: test._testMethodName})
AttributeError: '_ErrorHolder' object has no attribute '_testMethodName'

The relevant lines referenced are:

class JsonTestResult(TextTestResult):

    def __init__(self, stream, descriptions, verbosity=2):
        super(JsonTestResult, self).__init__(stream, descriptions, verbosity)
        self.successes = []

    def addSuccess(self, test):
        super(JsonTestResult, self).addSuccess(test)
        self.successes.append(test)

    def json_append(self, test, result, out, logs):
        suite = test.__class__.__name__
        if suite not in out:
            out[suite] = {TESTCASES: []}
        if result is PASS:
            out[suite][TESTCASES].append(
                {LOGS: logs, STATUS: result, TITLE: test._testMethodName})
        elif result is FAIL:
            out[suite][TESTCASES].append(
                {LOGS: logs, STATUS: result, TITLE: test._testMethodName})
        elif result is ERROR:
            out[suite][TESTCASES].append(
# LINE 93:
                {LOGS: logs, STATUS: result, TITLE: test._testMethodName})
        elif result is SKIP:
            out[suite][TESTCASES].append(
                {LOGS: logs, STATUS: result, TITLE: test._testMethodName})
        else:
            raise KeyError("No such result: {}".format(result))
        return out

    def jsonify(self):
        json_out = dict()
        for t in self.successes:
            json_out = self.json_append(t, PASS, json_out, None)

        for t, k in self.failures:
            json_out = self.json_append(t, FAIL, json_out, k)

        for t, k in self.errors:
# LINE 110:
            json_out = self.json_append(t, ERROR, json_out, k)

        for t, k in self.skipped:
            json_out = self.json_append(t, SKIP, json_out, k)

        if BROWSER == 'chrome' and PLATFORM == 'LINUX':
            output_path = "{0}/linux_chrome.json".format(OUTPUT_FILE)
            json.dump(json_out, open(output_path, 'w'))
        elif BROWSER == 'chrome' and PLATFORM == 'WINDOWS':
            output_path = "{0}/windows_chrome.json".format(OUTPUT_FILE)
            json.dump(json_out, open(output_path, 'w'))
        if BROWSER == 'chrome' and PLATFORM == 'MAC':
            output_path = "{0}/mac_chrome.json".format(OUTPUT_FILE)
            json.dump(json_out, open(output_path, 'w'))
        return json_out

if __name__ == '__main__':
    with open(os.devnull, 'w') as null_stream:
        runner = TextTestRunner(stream=null_stream)
        runner.resultclass = JsonTestResult

        suite = TestSuite([tests])

        # run the testsuite
        result = runner.run(suite)
        # print json output
# LINE 215:
        pprint(result.jsonify())

Tests run through a makefile command and outputs the results to a json file.

1
  • Can you show an example of one of your failing tests, and how you are running it? Commented May 3, 2018 at 7:59

2 Answers 2

3

It has something to do with the testsuite and the constructor for the derived object, which does not call the constructor of the super class correctly. Using Python 2.7 the error can be reproduced with:

import unittest

class T(unittest.TestCase):
    def __init__(self,x):
       # unittest.TestCase.__init__(self,x)
       pass

    def test_X(self):
        pass

if __name__ == '__main__':
    unittest.main()

If the call of the constructor of the base class is commented in, it worked for me. It also works, if I do not define the init at all.

Sign up to request clarification or add additional context in comments.

Comments

2

For me, the problem was my __init__ method.

Try this:

def __init__(self, methodName: str = ...) -> None:
    super().__init__(methodName)
    print("Inside __init__")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.