horizon/openstack_dashboard/dashboards/project/overview
Akihiro Motoki 1dd12d8deb test: Ensure to stop mock when create_mocks decorator exits
During reviewing https://review.opendev.org/c/openstack/horizon/+/772603,
we noticed that a method decorated by create_mocks is called multiple time
in a single test. Previously create_mocks decorator does not stop mocking,
so this means that multiple active mock can exist for one method.
In general, it is not a good idea to mock a method multiple times at the
same time.

To cope with this situation, this commit ensures for create_mocks decorator
to stop active mocks when exiting the decorator.

This works for most cases, but it does not work only when mocking and
assertions are handled by separate methods and test logic is placed between
them. To cope with this, "stop_mock" optional argument is introduced.

FYI: Details on why "stop_mock" is needed.
I explored various ways but could not find a good way so far.
create_mocks needs to be a decorator as it needs to refer an object
reference (self). On the other hand, if we would like to merge the logic of
mocking and assertions (for example, _stub_api_calls() and _check_api_calls()
in openstack_dashboard/dashboards/project/overview/tests.py), a context
manager would be good as we would like to call it inside a class.
However, we cannot mix a decorator and a context manger as a decorator is
executed when a context manager is iniitialized and stopping mock in
the create_mocks decorator is done during the initialization of the
context manager and methods are not mocked when test code is run.

Change-Id: I9e37dc1eaa08adf36d11975fed6f5a0a90cdde52
2021-02-26 18:44:11 +09:00
..
templates/overview Remove concatenation in csv file 2015-04-14 22:50:39 +00:00
__init__.py Splits OpenStack Dashboard bits from framework app code. 2012-10-11 11:47:50 -07:00
panel.py Allow horizon to function without nova 2016-07-26 09:15:48 -05:00
tests.py test: Ensure to stop mock when create_mocks decorator exits 2021-02-26 18:44:11 +09:00
urls.py Update URLs to Django 1.8+ style 2016-03-28 11:03:08 +01:00
views.py Use python3-style super() 2020-10-15 14:37:20 +09:00