Many projects use mocking in their unit tests, and most do not realize
that there is a difference between "import mock" and "import
unittest.mock", assuming that both use a standard part of the Python
library.
We've seen many cases where mock is not listed in the project's
requirements, but the code imports the third party mock instead of
unittest.mock. We've also seen a few break due to this, once their
dependencies have stopped pulling in that package for them.
There have also been several projects that have taken the effort to
switch all of there "import mock" statements over to "import
unittest.mock", as well as removing mock from their requirements, only
to then accidentally merge a patch that does "import mock" again because
it is hard to notice in code reviews.
This check is on by default. If a project is using the mock lib, then
they are able to explicitly do so by disabling this check. Otherwise,
projects don't need to take any action to get this protection, since
this is now the recommended default.
Change-Id: I8d255a00792a19279074703a8209a3699b480fd0
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This patch will copy the most common hacking rules used in diff.
projects and add them to hacking itself.
Currently, added assert_true_instance, assert_equal_type
assert_raises_regexp, assert_true_or_false_with_in
assert_equal_in
Change-Id: I122d250cab90964c346e9d53046a97c25054bc00
The regex for this check was wrong, resulting in misses. This fixes the
checks for string interpolation and adds unit tests to make sure we are
actually handling the cases we expect to be.
Change-Id: Id61094bb8ee8e93275c51c53caeb9ca27252b144
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
The mock third party library was needed for mock support in py2
runtimes. Since we now only support py36 and later, we don't need it
in lower-constraints and requirements.
These changes will help us to drop `mock` from openstack/requirements
Change-Id: I71a09f2eddd3a344225cb69f9679e99fdeb3e2db
According to Openstack summit session [1],
stestr is maintained project to which all Openstack projects should migrate.
Let's switch to stestr as other projects have already moved to it.
[1] https://etherpad.openstack.org/p/YVR-python-pti
Change-Id: I44170fcc60ad6e12d7badec354a96873e5cc91ea
This adds a placeholder file (like every other project has by default),
the source for the sphinx-generated release notes project, and the
appropriate requirements and tox environments.
Change-Id: I999b4f7014216361ba559158b13d776531dc8591
eventlet isn't actually used by hacking, but its a common global import
(nova/__init__.py imports it) in OpenStack, so to make the hacking venvs
work with local hacks in repos that require eventlet, we just add it
here.
Since this is a test-requirement it shouldn't have any impact on
packaging of hacking.
Change-Id: I81098fb4f4debc2654d60ed28a02d64c5bbcedea
Closes-Bug: 1403270
When running hacking from an oslo.* lib, all other oslo.* libs get
categorized as project because the import check was only looking at
the base module. So when running in oslo.db, oslo.db should be
categorized as project and oslo.config as third-party, but both were
being seen as project because _get_import_type was only looking at
the 'oslo' part of the import.
This change extends _get_import_type to look at the entire module
path and adds the necessary logic for handling namespace modules
and non-module imports. Since this is fairly complex and can't be
tested with doctests, standalone test cases are also added to verify
the behavior of the new code.
Note that prior to this change, oslo.db had 5 apparent H305
violations and 3 H307, which was incorrect. After this change,
hacking correctly reports 3 H305 violations and 1 H307.
Also, because some of the stdlib modules don't play nice with the
new lookup method, this also includes a static list of stdlib
modules that will also be used for py2/3 compatibility in a
followup commit.
Change-Id: Ibb8c982bafcd69c9d642e86aa357a3a11b4395af