{"action":"created","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest/issues/1558","repository_url":"https://api.github.com/repos/pytest-dev/pytest","labels_url":"https://api.github.com/repos/pytest-dev/pytest/issues/1558/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest/issues/1558/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest/issues/1558/events","html_url":"https://github.com/pytest-dev/pytest/issues/1558","id":155546995,"number":1558,"title":"Using __test__ in a class' method with metaclasses","user":{"login":"AbdealiJK","id":2200743,"avatar_url":"https://avatars.githubusercontent.com/u/2200743?v=3","gravatar_id":"","url":"https://api.github.com/users/AbdealiJK","html_url":"https://github.com/AbdealiJK","followers_url":"https://api.github.com/users/AbdealiJK/followers","following_url":"https://api.github.com/users/AbdealiJK/following{/other_user}","gists_url":"https://api.github.com/users/AbdealiJK/gists{/gist_id}","starred_url":"https://api.github.com/users/AbdealiJK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AbdealiJK/subscriptions","organizations_url":"https://api.github.com/users/AbdealiJK/orgs","repos_url":"https://api.github.com/users/AbdealiJK/repos","events_url":"https://api.github.com/users/AbdealiJK/events{/privacy}","received_events_url":"https://api.github.com/users/AbdealiJK/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pytest-dev/pytest/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/pytest-dev/pytest/labels/collection","name":"collection","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-18T16:32:09Z","updated_at":"2016-05-18T16:39:26Z","closed_at":null,"body":"We were using pytest in a python project where we had some metaclass manipulations of the unittest.TestCase. In the metaclass we added new functions dynamically and added it to the class. When doing this, we sometimes use `__test__ = False` to skip tests, but pytest still collects these methods.\r\n\r\nHere is an example:\r\n```python\r\nimport unittest\r\n\r\nclass ClassMeta(type):\r\n\r\n    def __new__(cls, name, bases, dct):\r\n        for name in ['abc', 'abc_not_run']:\r\n            test_name = 'test_metaclass_' + name\r\n            dct[test_name] = lambda self: None\r\n            dct[test_name].__name__ = test_name\r\n\r\n        dct['test_metaclass_abc_not_run'].__test__ = False\r\n        return super(ClassMeta, cls).__new__(cls, name, bases, dct)\r\n\r\nclass ClassMetaTest(unittest.TestCase):\r\n    __metaclass__ = ClassMeta\r\n```\r\nHere, I would expect `ClassMetaTest.test_metaclass_abc` to be collected and `ClassMetaTest.test_metaclass_abc_not_run` to not be collected. But they both get collected.\r\n\r\nNote that to debug I tried to conftest:\r\n```python\r\ndef pytest_runtest_setup(item):\r\n    print '\\n--- __test__ for', item, \"is\", getattr(item._obj, '__test__', None)\r\n```\r\n\r\nPyTest's output:\r\n```\r\n$ py.test --capture=no -vvv\r\n======================================= test session starts ========================================\r\nplatform linux2 -- Python 2.7.6, pytest-2.9.1, py-1.4.31, pluggy-0.3.1 -- /home/ajk/Documents/wiki/venv/bin/python\r\ncachedir: .cache\r\nrootdir: /home/ajk/Documents/wiki/pywikibot-core, inifile: tox.ini\r\nplugins: timeout-1.0.0, cov-2.2.1, xdist-1.14, env-0.6.0\r\ncollected 2 items \r\n\r\ntest_abc.py::ClassMetaTest::test_metaclass_abc \r\n--- __test__ for <TestCaseFunction 'test_metaclass_abc'> is None\r\nPASSED\r\ntest_abc.py::ClassMetaTest::test_metaclass_abc_not_run \r\n--- __test__ for <TestCaseFunction 'test_metaclass_abc_not_run'> is False\r\nPASSED\r\n\r\n===================================== 2 passed in 2.59 seconds =====================================\r\n```\r\n\r\nNosetests on the other hand ignores it:\r\n```\r\n$ nosetests -v abc.py\r\ntest_metaclass_abc (test_abc.abc_not_run) ... ok\r\n\r\n----------------------------------------------------------------------\r\nRan 1 test in 0.002s\r\n```\r\n\r\nCC @jayvdb "},"comment":{"url":"https://api.github.com/repos/pytest-dev/pytest/issues/comments/220085726","html_url":"https://github.com/pytest-dev/pytest/issues/1558#issuecomment-220085726","issue_url":"https://api.github.com/repos/pytest-dev/pytest/issues/1558","id":220085726,"user":{"login":"nicoddemus","id":1085180,"avatar_url":"https://avatars.githubusercontent.com/u/1085180?v=3","gravatar_id":"","url":"https://api.github.com/users/nicoddemus","html_url":"https://github.com/nicoddemus","followers_url":"https://api.github.com/users/nicoddemus/followers","following_url":"https://api.github.com/users/nicoddemus/following{/other_user}","gists_url":"https://api.github.com/users/nicoddemus/gists{/gist_id}","starred_url":"https://api.github.com/users/nicoddemus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicoddemus/subscriptions","organizations_url":"https://api.github.com/users/nicoddemus/orgs","repos_url":"https://api.github.com/users/nicoddemus/repos","events_url":"https://api.github.com/users/nicoddemus/events{/privacy}","received_events_url":"https://api.github.com/users/nicoddemus/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T16:39:26Z","updated_at":"2016-05-18T16:39:26Z","body":"Thanks.\r\n\r\nI think the `__test__` mechanism is used when collecting \"normal\" classes, py.test probably doesn't take that mechanism in account for `TestCase` subclasses."}}