mock: Perform patch's autospec checks on __enter__
Currently we're doing the autospec checks on __init__ (if the
target is autospecable), which will require importing modules
in some cases.
The mock.patch's constructor is called when a test module is being
loaded, before any set up could have been run, which can be problematic
in some cases (e.g.: some tested modules are importing platform specific
modules, and they couldn't have been mocked yet).
This patch moves the autospec checks to __enter__, which is executed
after the setUp.
Reviewed: https:/ /review. openstack. org/561581 /git.openstack. org/cgit/ openstack/ oslotest/ commit/ ?id=8241dd624f8 ca481fe15a44f7d 3fed10be7ae937
Committed: https:/
Submitter: Zuul
Branch: master
commit 8241dd624f8ca48 1fe15a44f7d3fed 10be7ae937
Author: Claudiu Belu <email address hidden>
Date: Fri Apr 13 10:33:12 2018 -0700
mock: Perform patch's autospec checks on __enter__
Currently we're doing the autospec checks on __init__ (if the
target is autospecable), which will require importing modules
in some cases.
The mock.patch's constructor is called when a test module is being
loaded, before any set up could have been run, which can be problematic
in some cases (e.g.: some tested modules are importing platform specific
modules, and they couldn't have been mocked yet).
This patch moves the autospec checks to __enter__, which is executed
after the setUp.
Related-Bug: #1735588
Change-Id: I9e10b34092ad79 5c7f9e58596fccc f4f37856225