From d3fbb097c1ecde6c10e7e9636bffd7bde43e49f1 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 25 Feb 2016 12:23:12 -0800 Subject: [PATCH] Add a hacking check for test method closures A recurring pattern when using multiple mocks is to create a closure decorated with mocks like: def test_thing(self): @mock.patch.object(self.compute, 'foo') @mock.patch.object(self.compute, 'bar') def _do_test(mock_bar, mock_foo): # Test things _do_test() However it is easy to leave off the _do_test() and have the test pass because nothing runs. This check looks for that pattern. Co-Authored-By: Andrew Laski Change-Id: I4c2395a01470acc7c9e5bcf1d3578d00270a2c07 --- HACKING.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HACKING.rst b/HACKING.rst index 4fab46782..6ae98dcb3 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -59,6 +59,7 @@ Nova Specific Commandments - [N346] Python 3: do not use dict.itervalues. - [N347] Provide enough help text for config options - [N348] Deprecated library function os.popen() +- [N349] Check for closures in tests which are not used Creating Unit Tests -------------------