[pitivi] tests: Allow debugging unit tests
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] tests: Allow debugging unit tests
- Date: Tue, 12 Apr 2022 09:59:43 +0000 (UTC)
commit 977ef09fba7a592963ee39ffec9af3a831a4e83b
Author: Robert Dyer <rdyer unl edu>
Date: Wed Apr 6 21:35:46 2022 +0000
tests: Allow debugging unit tests
Fixes #2604
docs/Debugging.md | 18 ++++++++++++++++++
tests/common.py | 12 ++++++++----
tests/ptv_testsuite.py | 6 ++++++
3 files changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/docs/Debugging.md b/docs/Debugging.md
index d724fcc56..bf9cfed71 100644
--- a/docs/Debugging.md
+++ b/docs/Debugging.md
@@ -33,3 +33,21 @@ Waiting for the debugger to attach...
```
Press `F5` in VS Code. If the Pitivi window shows up, your debugger is working.
+
+### Debugging Unit Tests
+
+You can also debug the unit tests by launching the test suite with the `PITIVI_VSCODE_DEBUG` environment
variable set to 1:
+
+```
+(ptv-flatpak) $ PITIVI_VSCODE_DEBUG=1 ptvtests
+[...]
+Waiting for the debugger to attach...
+```
+
+Note the test suite typically limits how long a test can run and will kill any test reaching the timeout
period. Thus, when you set a breakpoint in a test, you may have to increase the timeouts to avoid it being
killed while you debug:
+
+```
+(ptv-flatpak) $ PITIVI_VSCODE_DEBUG=1 ptvtests --timeout-factor 1000 [-t test_filename_or_method]
+[...]
+Waiting for the debugger to attach...
+```
diff --git a/tests/common.py b/tests/common.py
index 500f5e5ae..2a1ccb13f 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -154,13 +154,17 @@ def create_main_loop():
mainloop.quit()
def run(timeout_seconds=5, until_empty=False):
- source = GLib.timeout_source_new_seconds(timeout_seconds)
- source.set_callback(timeout_cb)
- source.attach()
+ # Limit the test running time only when not debugging.
+ debugging = os.environ.get("PITIVI_VSCODE_DEBUG", False)
+ if not debugging:
+ source = GLib.timeout_source_new_seconds(timeout_seconds)
+ source.set_callback(timeout_cb)
+ source.attach()
if until_empty:
GLib.idle_add(mainloop.quit, priority=GLib.PRIORITY_LOW + 1)
GLib.MainLoop.run(mainloop)
- source.destroy()
+ if not debugging:
+ source.destroy()
if timed_out:
raise Exception("Timed out after %s seconds" % timeout_seconds)
diff --git a/tests/ptv_testsuite.py b/tests/ptv_testsuite.py
index a379e7c23..e11e9a8a3 100644
--- a/tests/ptv_testsuite.py
+++ b/tests/ptv_testsuite.py
@@ -42,6 +42,12 @@ class PitiviTest(Test):
def setup_tests(test_manager, options):
"""Sets up Pitivi unit testsuite."""
+ if os.environ.get("PITIVI_VSCODE_DEBUG", False):
+ import debugpy
+ debugpy.listen(5678)
+ print("Waiting for the debugger to attach...")
+ debugpy.wait_for_client()
+
loader = unittest.TestLoader()
testsuites = loader.discover(CDIR)
for testsuite in testsuites:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]