Repository: pypa/pipx (python)

Issue:
No output from `pipx upgrade-all` when no packages have upgrades
**Describe the bug**

Before (in 1.4.x?), `pipx upgrade-all` used to print a message that said `No packages upgraded after running 'pipx upgrade-all'`.  After upgrading to 1.6.0 the message is gone, and `upgrade-all` produces no output (there is some output while it tries to upgrade the installed packages, but no output remains after the command is executed).

I'm not sure if this was an intentional change or a bug.  The code was recently changed in c9d31a6 (#1357 by @huxuan) and the message is still there:

https://github.com/pypa/pipx/blob/99c998dc3b798559ebf602fdbe8bb5a24f1c98dd/src/pipx/commands/upgrade.py#L264-L265

however I don't see it in the output, even while using `-v` (I see several other lines of output though).

**How to reproduce**

Make sure that all packages are upgraded, then run `pipx upgrade-all`.

**Expected behavior**

I would like to see a message stating that currently no package needs upgrades.


Pull request:
fix: no message when no packages upgraded with upgrade-all
<!-- add an 'x' in the brackets below -->

- [x] I have added a news fragment under `changelog.d/` (if the patch affects the end users)

## Summary of changes

Fix #1565

## Test plan

<!-- provide evidence of testing, preferably with command(s) that can be copy+pasted by others -->

Tested by running

```
# command(s) to exercise these changes
nox -s tests-3.10 -- -k test_upgrade_all_none
```


Patch:
diff --git a/changelog.d/1565.bugfix.md b/changelog.d/1565.bugfix.md
new file mode 100644
index 0000000..ee24a5a
--- /dev/null
+++ b/changelog.d/1565.bugfix.md
@@ -0,0 +1,1 @@
+Fix no message displayed when no packages are upgraded with `upgrade-all`.
diff --git a/src/pipx/commands/upgrade.py b/src/pipx/commands/upgrade.py
index c5ea6f4..89a4af0 100644
--- a/src/pipx/commands/upgrade.py
+++ b/src/pipx/commands/upgrade.py
@@ -247,7 +247,7 @@ def upgrade_all(
         if venv_dir.name in skip or "--editable" in venv.pipx_metadata.main_package.pip_args:
             continue
         try:
-            _upgrade_venv(
+            versions_updated = _upgrade_venv(
                 venv_dir,
                 venv.pipx_metadata.main_package.pip_args,
                 verbose=verbose,
@@ -256,11 +256,11 @@ def upgrade_all(
                 force=force,
                 python_flag_passed=python_flag_passed,
             )
+            if versions_updated > 0:
+                upgraded.append(venv_dir.name)
         except PipxError as e:
             print(e, file=sys.stderr)
             failed.append(venv_dir.name)
-        else:
-            upgraded.append(venv_dir.name)
     if len(upgraded) == 0:
         print(f"No packages upgraded after running 'pipx upgrade-all' {sleep}")
     if len(failed) > 0:


Test patch:
diff --git a/tests/test_upgrade_all.py b/tests/test_upgrade_all.py
index 4c65021..aebafe5 100644
--- a/tests/test_upgrade_all.py
+++ b/tests/test_upgrade_all.py
@@ -10,6 +10,7 @@ def test_upgrade_all(pipx_temp_env, capsys):
 
 
 def test_upgrade_all_none(pipx_temp_env, capsys):
+    assert not run_pipx_cli(["install", "pycowsay"])
     assert not run_pipx_cli(["upgrade-all"])
     captured = capsys.readouterr()
     assert "No packages upgraded after running 'pipx upgrade-all'" in captured.out