Skip to content

Commit 043fdb7

Browse files
committed
Displaying pip list command's packages and versions #5062
1 parent 7156752 commit 043fdb7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/_pytest/terminal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import collections
1111
import platform
12+
import subprocess
1213
import sys
1314
import time
1415

@@ -574,6 +575,11 @@ def pytest_sessionstart(self, session):
574575
):
575576
msg += " -- " + str(sys.executable)
576577
self.write_line(msg)
578+
pipe = subprocess.Popen("pip list", shell=True, stdout=subprocess.PIPE).stdout
579+
package_msg = pipe.read()
580+
package_msg = package_msg[:-2]
581+
if package_msg:
582+
self.write_line(package_msg)
577583
lines = self.config.hook.pytest_report_header(
578584
config=self.config, startdir=self.startdir
579585
)

testing/test_terminal.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,15 @@ def test_rewrite(self, testdir, monkeypatch):
278278
tr.rewrite("hey", erase=True)
279279
assert f.getvalue() == "hello" + "\r" + "hey" + (6 * " ")
280280

281+
def test_packages_display(self, testdir):
282+
testdir.makepyfile(
283+
"""
284+
def test_pass(num):
285+
assert 1 == 1"""
286+
)
287+
result = testdir.runpytest()
288+
result.stdout.fnmatch_lines(["*Package*", "*Version*"])
289+
281290

282291
class TestCollectonly(object):
283292
def test_collectonly_basic(self, testdir):

0 commit comments

Comments
 (0)