launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29551
[Merge] ~jugmac00/launchpad:add_how_to_test_scripts into launchpad:master
Jürgen Gmach has proposed merging ~jugmac00/launchpad:add_how_to_test_scripts into launchpad:master.
Commit message:
Add how-to test scripts
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/435875
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:add_how_to_test_scripts into launchpad:master.
diff --git a/doc/how-to/index.rst b/doc/how-to/index.rst
index 5ebddba..ea7b441 100644
--- a/doc/how-to/index.rst
+++ b/doc/how-to/index.rst
@@ -25,6 +25,7 @@ Common development tasks
land-update-for-loggerhead
update-configuration-for-testing
doc-theme
+ testing-scripts
Operating development instances
-------------------------------
diff --git a/doc/how-to/testing-scripts.rst b/doc/how-to/testing-scripts.rst
new file mode 100644
index 0000000..92ae02f
--- /dev/null
+++ b/doc/how-to/testing-scripts.rst
@@ -0,0 +1,30 @@
+===================
+Testing CLI scripts
+===================
+
+.. note::
+
+ This is about testing scripts within the Launchpad context,
+ not a general guide about testing CLI scripts.
+
+Launchpad offers a convenient test helper for testing scripts,
+which are usually found in the top level ``scripts`` folder.
+
+.. code-block:: python
+
+ from lp.services.scripts.tests import run_script
+
+ returncode, stdout, stderr = run_script(
+ script_relpath="scripts/script.py",
+ args=["--help"],
+ expect_returncode=0
+ )
+
+For more available options please have a look at the source code of
+``run_script``.
+
+.. note::
+
+ ``run_script`` uses a subprocess to run the script. This has impact on both
+ debugging via a Python debugger and on using ``strace``
+ (use ``strace -f``).
Follow ups