{"comment":{"url":"https://api.github.com/repos/ajschumacher/cnfg/comments/9857703","html_url":"https://github.com/ajschumacher/cnfg/commit/9083c84b04fb1391798e4bf495cd54c76a95f82e#commitcomment-9857703","id":9857703,"user":{"login":"Ooblioob","id":5611927,"avatar_url":"https://avatars.githubusercontent.com/u/5611927?v=3","gravatar_id":"","url":"https://api.github.com/users/Ooblioob","html_url":"https://github.com/Ooblioob","followers_url":"https://api.github.com/users/Ooblioob/followers","following_url":"https://api.github.com/users/Ooblioob/following{/other_user}","gists_url":"https://api.github.com/users/Ooblioob/gists{/gist_id}","starred_url":"https://api.github.com/users/Ooblioob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ooblioob/subscriptions","organizations_url":"https://api.github.com/users/Ooblioob/orgs","repos_url":"https://api.github.com/users/Ooblioob/repos","events_url":"https://api.github.com/users/Ooblioob/events{/privacy}","received_events_url":"https://api.github.com/users/Ooblioob/received_events","type":"User","site_admin":false},"position":32,"line":32,"path":"cnfg/test.py","commit_id":"9083c84b04fb1391798e4bf495cd54c76a95f82e","created_at":"2015-02-21T23:24:38Z","updated_at":"2015-02-21T23:24:38Z","body":"There are a couple of variations, but none that will line count significantly.  One alternative would be to put the decorators at the top of the class instead of each test method:\r\n```\r\n@mock.patch(\"os.path.join\")\r\n@mock.patch(\"os.path.expanduser\")\r\n@mock.patch(\"cnfg.contents_of\")\r\nclass TestLoad(unittest.TestCase):\r\n```\r\nThis will pass in the same mocks to any method that starts with \"test\".  Unfortunately, that means we can't make good use of the `setup()` method to reduce code in our test methods.  On the positive side, the only thing you'd have to add to each test method is what return values you want set (and that might be desirable in some situations), and it would allow us to remove the `start()` and `stop()` methods inside of `setup()`. However, given the number of test methods (plus any future ones) that would be a lot of duplication.\r\n```\r\ndef test_calls_os_path_join(self, contents_of_mock, expanduser_mock, join_mock):\r\n    join_mock.return_value = '~/a_file'\r\n    expanduser_mock.return_value = '/home/a_user/a_file'\r\n    contents_of_mock.return_value = \"{'a': 1,}\"\r\n    ...etc\r\n```\r\nNot the end of the world since it's test code (duplication is ok), but certainly a tradeoff.  "}}