Files
1dec542462324226aa7cfe8bf7767e7118cf38c0
nova /HACKING.rst

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

179 lines
8.7 KiB
ReStructuredText
Raw Normal View History

2010年05月27日 23:05:26 -07:00
Nova Style Commandments
=======================
https://docs.openstack.org/hacking/latest/
2010年05月27日 23:05:26 -07:00
---------------------------
2011年07月29日 12:49:48 -04:00
datetime.datetime.utcnow() to make it easy to override its return value in tests
Code that needs to be shared between virt drivers should be moved
into a common module
- [N312] using config vars from other virt drivers forbidden
Config parameters that need to be shared between virt drivers
should be moved into a common module
Config parameter help strings should have a capitalized first letter
assertIsInstance(A, B).
- [N317] Change assertEqual(type(A), B) by optimal assert like
assertIsInstance(A, B)
self.flags(option=value) instead.
assertIn/NotIn(A, B, message)
assertEqual(A in B, False) or assertEqual(False, A in B) to the more specific
assertIn/NotIn(A, B)
- [N356] Enforce use of assertIs/assertIsNot
generate UUID instead of uuid4().
assertNotRegexpMatches
not "from nova.privsep import path". This ensures callers know that the method they're
calling is using privilege escalation.
- [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.
fasteners.ReaderWriterLock() does not function correctly
with eventlet patched code. Use nova.utils.ReaderWriterLock() instead.
- [N370] Don't use or import six
- [N371] You must explicitly import python's mock: ``from unittest import mock``
from stdlib instead. E.g. eventlet.sleep => time.sleep
-------------------
For every new feature, unit tests should be created that both test and
(implicitly) document the usage of said feature. If submitting a patch for a
bug that had no unit test, a new passing unit test should be added. If a
submitted bug fix does have a unit test, be sure to add a new one that fails
without the patch and passes with the patch.
For more information on creating unit tests and utilizing the testing
Running Tests
-------------
create virtual environments, populate them with dependencies and run all of
stestr arguments that are needed to tox. For example, you can run:
``tox -- --analyze-isolation`` to cause tox to tell stestr to add
the class name containing the tests as an extra ``tox`` argument;
e.g. ``tox -- TestWSGIServer`` (note the double-hypen) will test all
``-- TestWSGIServer|TestWSGIServerWithSSL`` would run tests from both
classes.
you have created, or it is possible that you have all of the dependencies
command directly. Running ``stestr run`` will run the entire test suite.
``stestr run --concurrency=1`` will run tests serially (by default, stestr runs
tests in parallel). More information about stestr can be found at:
http://stestr.readthedocs.io/
Make it easier to run a selection of tests relevant to ongoing work During development of a new git commit, locally running a whole unit or functional test suite to check every minor code change is prohibitively expensive. For maximum developer productivity and happiness, it's generally desirable to make the feedback loop of the traditional red/green cycle as quick as possible. So add run-tests-for-diff.sh and run-tests.py to the tools/ subdirectory, using a few tricks as explained below to help with this. run-tests.py takes a list of files on STDIN, filters the list for tests which can be run in the current tox virtualenv, and then runs them with the correct stestr options. run-tests-for-diff.sh is a simple wrapper around run-tests.py which determines which tests to run using output from "git diff". This allows running only the test files changed/added in the working tree: tools/run-tests-for-diff.sh or by a single commit: tools/run-tests-for-diff.sh mybranch^! or a range of commits, e.g. a branch containing a whole patch series for a blueprint: tools/run-tests-for-diff.sh gerrit/master..bp/my-blueprint It supports the same "-HEAD" invocation syntax as flake8wrap.sh (as used by the "fast8" tox environment): tools/run-tests-for-diff.sh -HEAD run-tests.py uses two tricks to make test runs as quick as possible: 1. It's (already) possible to speed up running of tests by source'ing the "activate" file for the desired tox virtualenv, e.g. source .tox/py36/bin/activate and then running stestr directly. This saves a few seconds by skipping the overhead introduced by running tox. 2. When only one test file needs to be run, specifying the -n option to stestr will skip the costly test discovery phase, saving several more valuable seconds. Future commits could build on top of this work, harnessing a framework such as watchdog / watchmedo[0] or Guard[1] in order to automatically run relevant tests every time your editor saves changes to a .py file. [0] https://github.com/gorakhargosh/watchdog - Python-based [1] https://guardgem.org - probably best in class, but Ruby-based so maybe unacceptable for use within Nova. Change-Id: I9a9bda5d29bbb8d8d77f769cd1abf7c42a18c36b
2019年08月19日 11:31:59 +01:00
Since when testing locally, running the entire test suite on a regular
basis is prohibitively expensive, the ``tools/run-tests-for-diff.sh``
script is provided as a convenient way to run selected tests using
output from ``git diff``. For example, this allows running only the
test files changed/added in the working tree::
tools/run-tests-for-diff.sh
However since it passes its arguments directly to ``git diff``, tests
can be selected in lots of other interesting ways, e.g. it can run all
tests affected by a single commit at the tip of a given branch::
tools/run-tests-for-diff.sh mybranch^!
or all those affected by a range of commits, e.g. a branch containing
a whole patch series for a blueprint::
tools/run-tests-for-diff.sh gerrit/master..bp/my-blueprint
It supports the same ``-HEAD`` invocation syntax as ``flake8wrap.sh``
(as used by the ``fast8`` tox environment)::
tools/run-tests-for-diff.sh -HEAD
log at ``DEBUG`` level by exporting the ``OS_DEBUG`` environment
variable to ``True``.
-------------
which will cause a virtualenv with all of the needed dependencies to be
created and then inside of the virtualenv, the docs will be created and
put into doc/build/html.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you'd like a PDF of the documentation, you'll need LaTeX and ImageMagick
installed, and additionally some fonts. On Ubuntu systems, you can get what you
need with::
Then you can use the ``build_latex_pdf.sh`` script in tools/ to take care
of both the sphinx latex generation and the latex compilation. For example::
output pdf to Nova.pdf in that directory.