Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go to discover tests directory after login #3357

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading