If you work in a team from a Linux laptop and have a test that runs for a long time, you probably want your teammates to be able to check its status too — live, without you having to report back.
That was my situation: a long-duration pytest run on an Ubuntu laptop. The tool that solved it was tmux. Ubuntu packages it, it installs with one command, and anyone on the team who can SSH into the laptop — even from a Windows laptop — can watch the same terminal I am looking at while I carry on with other work.
How tmux helps here
tmux keeps your terminal session running inside a background server on the laptop, separate from the terminal window you are looking at. That gives you two things a long test run needs:
- The session outlives your terminal. Close the window, or lose your SSH connection, and the session — with the test inside it — keeps running.
- Several people can attach to the same session at once, and all of them see the same screen as it updates.
1. Install it
sudo apt install tmux
tmux -V
tmux -V prints the installed version, which confirms it worked.
2. Start a named session and run the test
First, see whether any sessions already exist:
tmux ls
If there are none, this prints an error — no server running on … or error connecting to … —
instead of an empty list. That just means there are no sessions yet.
To start a session, plain tmux works. But it names the session 0 (then 1, 2, and so on),
which is not much to tell a teammate. Give it a name instead:
tmux new -s longtest
You are now inside the session. Start the test exactly as you normally would:
pytest tests/
3. Detach, and leave it running
To step out of the session without stopping anything, press Ctrl+b, release, then press d.
You are back at your normal prompt, tmux ls now lists longtest, and the test is still running
inside it. You can close the terminal.
To go back in yourself:
tmux attach -t longtest
or the short form, which does the same thing:
tmux a -t longtest
tmux accepts the shortest unambiguous form of any command, and a can only mean attach-session.
One limit to know: tmux keeps the test running when a terminal closes or an SSH connection drops. It cannot keep it running if the laptop goes to sleep, because suspending freezes every running program, tmux included. Keep the laptop awake for the length of the run.
4. Let your teammates watch
On the laptop, find its IP address:
hostname -I
If the laptop has more than one network interface, this prints more than one address. Use the one on the network your teammates are on.
If the laptop does not accept SSH connections yet, install the SSH server on it:
sudo apt install openssh-server
Your teammates can then connect and attach:
# on your teammate's machine
ssh your-username@192.168.1.50 # the account that started the session
tmux attach -r -t longtest # this now runs on the laptop
The short form works here too: tmux a -r -t longtest.
From a Windows laptop, run the same ssh command in PowerShell, then the same tmux attach
once you are logged in. If Windows says ssh is not recognised, add OpenSSH Client under
Optional Features in Windows Settings.
Two things decide whether this works.
Everyone logs in as the user who started the session. tmux runs a separate server for each user
account, with its socket in /tmp/tmux-<UID>/, and by default only that user (and root) can reach
it. A teammate who SSHes in with their own account and runs tmux ls is asking their own, empty
server — your session is simply not there. The simple setup, and the one this post assumes, is that
teammates connect as the account that started the session. Letting other accounts attach is
possible, but it means changing the socket’s file permissions by hand and, on tmux 3.3 and later,
granting access with the server-access command — see man tmux.
Attach with -r, for read-only. Without it, whatever a teammate types goes into the session, so
a Ctrl+C meant for their own terminal stops your test run. With -r, tmux ignores their keystrokes
except the ones that detach or switch sessions, and their terminal size does not affect yours.
-r guards against accidental keystrokes, not against misuse: anyone who can SSH in as that
account can already do anything that account can.
To leave, a teammate presses Ctrl+b, then d, the same as you. That works in read-only mode too.
5. When the run finishes
When pytest finishes, the session stays open with the final summary on screen, so anyone who attaches afterwards can still read it. Once everyone has seen it, close the session:
tmux kill-session -t longtest
If you want something more shareable than a terminal summary, I wrote up turning pytest results into an HTML report in installing and using Allure on Windows and Linux.
Test runs are not the only thing worth leaving attached. Watching a clock settle is another — see
setting up PTP on Linux, where phc2sys prints
a line a second and you want to come back to it rather than sit with it.
Cheat sheet
| Where | Command | What it does |
|---|---|---|
| Laptop | sudo apt install tmux |
Install tmux |
| Laptop | tmux ls |
List existing sessions |
| Laptop | tmux new -s longtest |
Start a session called longtest |
| Inside tmux | Ctrl+b, then d | Detach — the test keeps running |
| Laptop | tmux attach -t longtest or tmux a -t longtest |
Go back in |
| Laptop | hostname -I |
Find the address teammates connect to |
| Laptop | sudo apt install openssh-server |
Accept SSH connections, if not already set up |
| Teammate | ssh your-username@<laptop-ip> |
Log in as the user who started the session |
| Teammate | tmux attach -r -t longtest |
Watch live, read-only |
| Laptop | tmux kill-session -t longtest |
Close the session when done |
References
- tmux manual — https://man.openbsd.org/tmux.1
- tmux on Ubuntu — https://packages.ubuntu.com/search?keywords=tmux&searchon=names&exact=1&suite=all§ion=all
- OpenSSH server on Ubuntu — https://documentation.ubuntu.com/server/how-to/security/openssh-server/
- OpenSSH on Windows — https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
That is all I needed for my long pytest run. If you have come across a simpler or better way to share a long-running job live with your team, tell me in the comments what it is. And if your teammates log in with their own accounts rather than a shared one, I would like to hear how you set that up.
Questions or comments?
Ask a question, share your experience, or add a correction below.