Skip to content

Commit

Permalink
Merge pull request #1304 from vojtechtrefny/main_tests-logging
Browse files Browse the repository at this point in the history
Allow enabling logging when running tests
  • Loading branch information
vojtechtrefny authored Oct 11, 2024
2 parents 10a69fc + 1724f44 commit a8c6688
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plans/tests.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ prepare:

execute:
how: tmt
script: sudo make test
script:
- sudo python3 tests/run_tests.py -l
- tmt-file-submit -l /tmp/blivet.log
11 changes: 11 additions & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def addFailure(self, test, err): # pylint: disable=redefined-outer-name
help="name of test class or method (e. g. 'devices_test' or 'formats_test.fs_test.Ext2FSTestCase'")
argparser.add_argument("-p", "--pdb", dest="pdb", help="run pdb after a failed test", action="store_true")
argparser.add_argument("-s", "--stop", dest="stop", help="stop executing after first failed test", action="store_true")
argparser.add_argument("-l", "--logging", dest="logging", help="enable blivet logging during tests", action="store_true")
argparser.add_argument("-d", "--log-dir", dest="logdir",
help="directory for saving the logs (defaults to current directory)",
action="store")
args = argparser.parse_args()

testdir = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -258,6 +262,13 @@ def addFailure(self, test, err): # pylint: disable=redefined-outer-name

suite.addTest(test)

if args.logging:
from blivet.util import set_up_logging
if args.logdir:
set_up_logging(log_dir=args.logdir)
else:
set_up_logging()

if args.pdb:
runner = unittest.TextTestRunner(verbosity=2, failfast=args.stop, resultclass=DebugTestResult)
else:
Expand Down

0 comments on commit a8c6688

Please sign in to comment.