From 0996f3dbc54d5b0d096e7341cb6718ffd16da100 Mon Sep 17 00:00:00 2001 From: danielx123 Date: Mon, 22 Apr 2019 18:23:51 -0400 Subject: [PATCH] Displaying pip list command's packages and versions #5062 --- src/_pytest/terminal.py | 6 ++++++ testing/test_terminal.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 2d7132259..98cbaa571 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -9,6 +9,7 @@ from __future__ import print_function import argparse import collections import platform +import subprocess import sys import time from functools import partial @@ -581,6 +582,11 @@ class TerminalReporter(object): ): 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 ) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index feacc242d..bfa928d74 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -279,6 +279,15 @@ class TestTerminal(object): 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):