diff options
author | Balazs Gibizer <balazs.gibizer@est.tech> | 2021-08-23 19:23:31 +0200 |
---|---|---|
committer | Lee Yarwood <lyarwood@redhat.com> | 2021-09-01 12:26:52 +0100 |
commit | 9f8cc2f03827c10f89ee652bc73790b3c58111d3 (patch) | |
tree | 98e6f68bec83a0aeb52f9050cae76f865d61ae68 /HACKING.rst | |
parent | 7c1ca501eeeb6aa0067327b4f37d06244987e953 (diff) | |
download | nova-9f8cc2f03827c10f89ee652bc73790b3c58111d3.tar.gz |
Add two new hacking rules
As the bug and fix If71620e808744736cb4fe3abda76d81a6335311b showed
it is dangerous to forget instantiating the Mock class before it is
used in the test as changes on the class directly leaks out from the
test. In almost all the cases using Mock class directly is a bug and the
author original intention is to use an instance instead, just forgot
about the parents. So this patch adds two new hacking rules:
N367: catches the case when Mock class is aliased in the test:
self.mock_mystuff = mock.Mock
N368: catches when mock.patch instructed to use the Mock class as
replacement value during patching:
mock.patch('Bar.foo', new=mock.Mock)
For N367 the previous patch removed the last hit. For N368 this patch
removes the two hits exists.
Change-Id: Id42ca571b1569886ef47aa350369e9d2068e77bc
Related-Bug: #1936849
Diffstat (limited to 'HACKING.rst')
-rw-r--r-- | HACKING.rst | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/HACKING.rst b/HACKING.rst index 76ff4b6c22..0f98901864 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -68,6 +68,9 @@ Nova Specific Commandments - [N364] Check non-existent mock assertion methods and attributes. - [N365] Check misuse of assertTrue/assertIsNone. - [N366] The assert_has_calls is a method rather than a variable. +- [N367] Disallow aliasing the mock.Mock and similar classes in tests. +- [N368] Reject if the mock.Mock class is used as a replacement value instead of and + instance of a mock.Mock during patching in tests. Creating Unit Tests ------------------- |