Skip to content

Commit

Permalink
Displaying pip list command's packages and versions #5062
Browse files Browse the repository at this point in the history
  • Loading branch information
danielx123 committed Apr 22, 2019
1 parent 7156752 commit 043fdb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import argparse
import collections
import platform
import subprocess
import sys
import time

Expand Down Expand Up @@ -574,6 +575,11 @@ def pytest_sessionstart(self, session):
):
msg += " -- " + str(sys.executable)
self.write_line(msg)
pipe = subprocess.Popen("pip list", shell=True, stdout=subprocess.PIPE).stdout
package_msg = pipe.read()
package_msg = package_msg[:-2]
if package_msg:
self.write_line(package_msg)
lines = self.config.hook.pytest_report_header(
config=self.config, startdir=self.startdir
)
Expand Down
9 changes: 9 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ def test_rewrite(self, testdir, monkeypatch):
tr.rewrite("hey", erase=True)
assert f.getvalue() == "hello" + "\r" + "hey" + (6 * " ")

def test_packages_display(self, testdir):
testdir.makepyfile(
"""
def test_pass(num):
assert 1 == 1"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*Package*", "*Version*"])


class TestCollectonly(object):
def test_collectonly_basic(self, testdir):
Expand Down

0 comments on commit 043fdb7

Please sign in to comment.