[tracker-miners/sam/test-fixes: 5/8] Add TRACKER_DEBUG=tests-no-cleanup
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/test-fixes: 5/8] Add TRACKER_DEBUG=tests-no-cleanup
- Date: Fri, 1 May 2020 23:41:22 +0000 (UTC)
commit b551a75fc26729743d38eecfe39da3898aeb94d0
Author: Sam Thursfield <sam afuera me uk>
Date: Fri May 1 21:40:15 2020 +0200
Add TRACKER_DEBUG=tests-no-cleanup
This causes the functional tests to save the data directory.
Something I constantly finding myself modifying the source code
to do when debugging them.
tests/functional-tests/configuration.py | 46 ++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 9 deletions(-)
---
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index b8b955f77..3f3d96c0e 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -19,6 +19,8 @@
#
+from gi.repository import GLib
+
import errno
import json
import logging
@@ -83,16 +85,19 @@ def create_monitored_test_dir():
def remove_monitored_test_dir(path):
- shutil.rmtree(path)
+ if tests_no_cleanup():
+ print("\nTRACKER_DEBUG=tests-no-cleanup: Test data kept in %s" % path)
+ else:
+ shutil.rmtree(path)
- # We delete the parent directory if possible, to avoid cluttering the user's
- # home dir, but there may be other tests running in parallel so we ignore
- # an error if there are still files present in it.
- try:
- os.rmdir(_TEST_MONITORED_TMP_DIR)
- except OSError as e:
- if e.errno == errno.ENOTEMPTY:
- pass
+ # We delete the parent directory if possible, to avoid cluttering the user's
+ # home dir, but there may be other tests running in parallel so we ignore
+ # an error if there are still files present in it.
+ try:
+ os.rmdir(_TEST_MONITORED_TMP_DIR)
+ except OSError as e:
+ if e.errno == errno.ENOTEMPTY:
+ pass
def get_environment_boolean(variable):
@@ -117,3 +122,26 @@ def get_environment_int(variable, default=0):
def tests_verbose():
return get_environment_boolean('TRACKER_TESTS_VERBOSE')
+
+
+DEBUG_TESTS_NO_CLEANUP = 1
+
+_debug_flags = None
+def get_debug_flags():
+ """Parse the TRACKER_DEBUG environment variable and return flags."""
+ global _debug_flags
+ if _debug_flags is None:
+ flag_tests_no_cleanup = GLib.DebugKey()
+ flag_tests_no_cleanup.key = 'tests-no-cleanup'
+ flag_tests_no_cleanup.value = DEBUG_TESTS_NO_CLEANUP
+
+ flags = [flag_tests_no_cleanup]
+ flags_str = os.environ.get('TRACKER_DEBUG', '')
+
+ _debug_flags = GLib.parse_debug_string(flags_str, flags)
+ return _debug_flags
+
+
+def tests_no_cleanup():
+ """True if TRACKER_DEBUG=tests-no-cleanup"""
+ return(get_debug_flags() & DEBUG_TESTS_NO_CLEANUP)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]