The previous only worked for code from kojihub.py. Any hub module that imported QueryProcessor differently would not see the mock. This approach mocks the class in place so that all imports will see it.
While here, I noticed this bit of test code:
def setUp(self):
mock.patch.stopall()
It makes no sense to stop mock patches in setUp. At this point, there should be no active patches unless other tests are misbehaving. As it turns out, a great many of our tests were failing to properly clean up. Removing the above stopall broke several tests, which was probably what prompted #2758.
Having stray mocks lingering after a unit test is completed could potentially mask a later unit test, or as seen here break one in a hard to debug way.
The previous only worked for code from kojihub.py. Any hub module that imported QueryProcessor differently would not see the mock. This approach mocks the class in place so that all imports will see it.
While here, I noticed this bit of test code:
It makes no sense to stop mock patches in setUp. At this point, there should be no active patches unless other tests are misbehaving. As it turns out, a great many of our tests were failing to properly clean up. Removing the above
stopallbroke several tests, which was probably what prompted #2758.Having stray mocks lingering after a unit test is completed could potentially mask a later unit test, or as seen here break one in a hard to debug way.
Fixes: https://pagure.io/koji/issue/4071
Related: https://pagure.io/koji/issue/2758