{"action":"created","issue":{"url":"https://api.github.com/repos/nose-devs/nose2/issues/253","labels_url":"https://api.github.com/repos/nose-devs/nose2/issues/253/labels{/name}","comments_url":"https://api.github.com/repos/nose-devs/nose2/issues/253/comments","events_url":"https://api.github.com/repos/nose-devs/nose2/issues/253/events","html_url":"https://github.com/nose-devs/nose2/issues/253","id":109635878,"number":253,"title":"Module level coverage missing","user":{"login":"frenchtoast747","id":1094000,"avatar_url":"https://avatars.githubusercontent.com/u/1094000?v=3","gravatar_id":"","url":"https://api.github.com/users/frenchtoast747","html_url":"https://github.com/frenchtoast747","followers_url":"https://api.github.com/users/frenchtoast747/followers","following_url":"https://api.github.com/users/frenchtoast747/following{/other_user}","gists_url":"https://api.github.com/users/frenchtoast747/gists{/gist_id}","starred_url":"https://api.github.com/users/frenchtoast747/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frenchtoast747/subscriptions","organizations_url":"https://api.github.com/users/frenchtoast747/orgs","repos_url":"https://api.github.com/users/frenchtoast747/repos","events_url":"https://api.github.com/users/frenchtoast747/events{/privacy}","received_events_url":"https://api.github.com/users/frenchtoast747/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-03T17:51:51Z","updated_at":"2015-10-24T20:31:38Z","closed_at":null,"body":"Say I have the coverage plugin installed, configured, and enabled and I have a simple test:\r\n\r\n```.py\r\nfrom unittest import TestCase\r\n\r\nfrom my_module import returns_42\r\n\r\nclass MyTest(TestCase):\r\n    def test_it(self):\r\n        self.assertEqual(returns_42(), 42)\r\n```\r\n\r\nThe test passes and all is good until I have a look at coverage report. The module level coverage is absent, but the function level coverage is present:\r\n\r\n![coverage](https://cloud.githubusercontent.com/assets/1094000/10264286/a829f566-69cc-11e5-80a7-5e8ceadeea37.png)\r\n\r\nAccording to [this StackOverflow question](http://stackoverflow.com/questions/9155854/getting-pythons-coverage-py-to-gather-coverage-for-the-module-that-imports-it), this behavior implies that coverage isn't being collected until *after* the test starts.\r\n\r\nA work around would be to do something like this:\r\n\r\n```.py\r\nfrom unittest import TestCase\r\n\r\nclass MyTest(TestCase):\r\n    def test_it(self):\r\n        from my_module import returns_42\r\n        self.assertEqual(returns_42(), 42)\r\n```\r\n\r\nwhich gives me the coverage I expect:\r\n\r\n![coverage_i_expect](https://cloud.githubusercontent.com/assets/1094000/10264315/5916960e-69cd-11e5-97de-57a17111fea6.png)\r\n\r\nhowever, that's not what I would consider an ideal solution. Is there an option or a setting that I am missing to fix this? Is there something else that I am missing?"},"comment":{"url":"https://api.github.com/repos/nose-devs/nose2/issues/comments/150848036","html_url":"https://github.com/nose-devs/nose2/issues/253#issuecomment-150848036","issue_url":"https://api.github.com/repos/nose-devs/nose2/issues/253","id":150848036,"user":{"login":"ztane","id":704200,"avatar_url":"https://avatars.githubusercontent.com/u/704200?v=3","gravatar_id":"","url":"https://api.github.com/users/ztane","html_url":"https://github.com/ztane","followers_url":"https://api.github.com/users/ztane/followers","following_url":"https://api.github.com/users/ztane/following{/other_user}","gists_url":"https://api.github.com/users/ztane/gists{/gist_id}","starred_url":"https://api.github.com/users/ztane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ztane/subscriptions","organizations_url":"https://api.github.com/users/ztane/orgs","repos_url":"https://api.github.com/users/ztane/repos","events_url":"https://api.github.com/users/ztane/events{/privacy}","received_events_url":"https://api.github.com/users/ztane/received_events","type":"User","site_admin":false},"created_at":"2015-10-24T20:31:38Z","updated_at":"2015-10-24T20:31:38Z","body":"@frenchtoast747 actually it seems to be fixed at https://github.com/nose-devs/nose2/commit/268371d815fb319bda4489da9756843204354eab"}}