{"action":"opened","issue":{"url":"https://api.github.com/repos/CleanCut/green/issues/93","labels_url":"https://api.github.com/repos/CleanCut/green/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/CleanCut/green/issues/93/comments","events_url":"https://api.github.com/repos/CleanCut/green/issues/93/events","html_url":"https://github.com/CleanCut/green/issues/93","id":111136702,"number":93,"title":"Class name detection fails for metaclass","user":{"login":"jayvdb","id":15092,"avatar_url":"https://avatars.githubusercontent.com/u/15092?v=3","gravatar_id":"","url":"https://api.github.com/users/jayvdb","html_url":"https://github.com/jayvdb","followers_url":"https://api.github.com/users/jayvdb/followers","following_url":"https://api.github.com/users/jayvdb/following{/other_user}","gists_url":"https://api.github.com/users/jayvdb/gists{/gist_id}","starred_url":"https://api.github.com/users/jayvdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayvdb/subscriptions","organizations_url":"https://api.github.com/users/jayvdb/orgs","repos_url":"https://api.github.com/users/jayvdb/repos","events_url":"https://api.github.com/users/jayvdb/events{/privacy}","received_events_url":"https://api.github.com/users/jayvdb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-13T08:59:34Z","updated_at":"2015-10-13T08:59:34Z","closed_at":null,"body":"green reports an error when running a test case which uses a metaclasses, and also reports the wrong name for the test class. (see `__doc__` and `green.result` appearing below)\r\n\r\n```\r\n$ green -vvv tests.tools_tests\r\ntests: max_retries reduced from 25 to 1\r\nGreen 2.0.7, Coverage 3.7, Python 2.7.5\r\n\r\ntests.tools_tests\r\n  ContextManagerWrapperTestCase\r\n.   Check that the wrapper permits exceptions.\r\n.   Create a test instance and verify the wrapper redirects.\r\n.....\r\n  __doc__\r\n.   Test getargspec on args.\r\n.   Test getargspec on kwargs.\r\n.   Test getargspec on varargs.\r\n.   Test getargspec on varkwargs.\r\n.   Test getargspec on vars.\r\n.....\r\ngreen.result\r\n  ProtoTestResult\r\n.   Test getargspec on kwargs.\r\n.   Test getargspec on varkwargs.\r\n    errors[],Traceback (most recent call last):\r\n  File \"/usr/bin/green\", line 9, in <module>\r\n    load_entry_point('green==2.0.7', 'console_scripts', 'green')()\r\n  File \"/usr/lib/python2.7/site-packages/green/cmdline.py\", line 75, in main\r\n    result = run(test_suite, stream, args, testing)\r\n  File \"/usr/lib/python2.7/site-packages/green/runner.py\", line 118, in run\r\n    result.addProtoTestResult(proto_test_result)\r\n  File \"/usr/lib/python2.7/site-packages/green/result.py\", line 337, in addProtoTestResult\r\n    for test, err in proto_test_result.errors:\r\nAttributeError: 'NoneType' object has no attribute 'errors'\r\n<type 'exceptions.AttributeError'>\r\nCRITICAL: Closing network session.\r\n```\r\n\r\nThe top level entry `  __doc__` in the above is a metaclassed test class, and it is failing to get the class name/docstring correct, but otherwise works OK:\r\nhttps://github.com/wikimedia/pywikibot-core/blob/master/tests/tools_tests.py#L521\r\n\r\nThen the failure occurs on the 'next' test class, which inherits from the metaclass\r\n\r\nhttps://github.com/wikimedia/pywikibot-core/blob/master/tests/tools_tests.py#L555\r\n\r\nReturning to the `__doc__` entry, I can fix that by sorting the names of the methods being created in `__new__`, e.g.\r\n\r\n```diff\r\ndiff --git a/tests/tools_tests.py b/tests/tools_tests.py\r\nindex c58e33f..bdccb2f 100644\r\n--- a/tests/tools_tests.py\r\n+++ b/tests/tools_tests.py\r\n@@ -506,7 +506,8 @@ class MetaTestArgSpec(MetaTestCaseClass):\r\n                 self.assertNoDeprecation()\r\n             return test_method\r\n \r\n-        for name, tested_method in list(dct.items()):\r\n+        for name in sorted(list(dct.keys())):\r\n+            tested_method = dct[name]\r\n             if name.startswith('_method_test_'):\r\n                 suffix = name[len('_method_test_'):]\r\n                 cls.add_method(dct, 'test_method_' + suffix,\r\n```\r\n\r\ncauses the `green` output to be\r\n\r\n```\r\n...\r\n  getargspec\r\n.   Test getargspec on args.\r\n.   Test getargspec on kwargs.\r\n.   Test getargspec on varargs.\r\n.   Test getargspec on varkwargs.\r\n.   Test getargspec on vars.\r\n...\r\n```"}}