Skip to content

Commit

Permalink
Go to discover tests directory after login (#3357)
Browse files Browse the repository at this point in the history
Co-authored-by: Ismail Ibrahim Quwarah <[email protected]>
Co-authored-by: Petr Šplíchal <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent e12ded3 commit 3afd8ae
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Documentation pages now use the `new tmt logo`__ designed by Maria Leonova.

__ https://github.com/teemtee/docs/tree/main/logo

When the ``login`` command is used to enter an interactive session
on the guest, for example during the ``tmt try`` command, the
current working directory is set to the path of the last
executed test, so that users can easily investigate the test
code there and experiment with it directly on the guest.


tmt-1.39.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
15 changes: 15 additions & 0 deletions tests/try/basic/data/test-dir.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/expect -f
# Try login to test directory

set timeout 180
spawn tmt try fedora@container

expect "What do we do next?"
send -- "l\r"
expect "#"
send -- "ls\r"
send -- "exit\r"

expect "What do we do next?"
send -- "q\r"
expect eof
Empty file.
9 changes: 9 additions & 0 deletions tests/try/basic/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ rlJournalStart
rlRun "popd"
rlPhaseEnd

rlPhaseStartTest "Tests directory after login"
rlRun "pushd tests/core/bad"
rlRun -s "TMT_CONFIG_DIR=$tmp ../../../test-dir.exp" 0 "Try with container"
rlAssertGrep "Let's try /tests/core/bad with /default/plan" $rlRun_LOG
rlAssertGrep "summary: 1 test executed" $rlRun_LOG
rlAssertGrep "bad-file.txt" $rlRun_LOG
rlRun "popd"
rlPhaseEnd

rlPhaseStartTest "Three Tests (user plan, verbose)"
rlRun "pushd tests/core"
rlRun -s "TMT_CONFIG_DIR=$config ../../verbose.exp" 0 "Try with local"
Expand Down
17 changes: 16 additions & 1 deletion tmt/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,22 @@ def _login(
# Attempt to push the workdir to the guest
try:
guest.push()
cwd = cwd or self.parent.plan.worktree
if not cwd:
# Use path of the last executed test as the default
# current working directory
worktree = self.parent.plan.worktree
tests = self.parent.plan.discover.tests()
test_path = tests[-1].path if tests else None
if test_path is None or worktree is None:
cwd = worktree
else:
try:
cwd = worktree.parent / "discover" / test_path.unrooted()
guest.execute(tmt.utils.ShellScript("/bin/true"),
interactive=True, cwd=cwd, env=env)
except RunError:
cwd = worktree

except tmt.utils.GeneralError:
self.warn("Failed to push workdir to the guest.")
cwd = None
Expand Down

0 comments on commit 3afd8ae

Please sign in to comment.