From 71567523d50d35694b1e15d815fe1323f16886f8 Mon Sep 17 00:00:00 2001 From: danielx123 Date: Mon, 22 Apr 2019 17:58:07 -0400 Subject: [PATCH 1/3] Adding test cases for unrolling an iterable #5062 --- testing/test_assertrewrite.py | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 72bfbcc55af..2786147e264 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -671,6 +671,53 @@ def __repr__(self): assert "UnicodeDecodeError" not in msg assert "UnicodeEncodeError" not in msg + def test_generator(self, testdir): + testdir.makepyfile( + """ + def check_even(num): + if num % 2 == 0: + return True + return False + + def test_generator(): + odd_list = list(range(1,9,2)) + assert all(check_even(num) for num in odd_list)""" + ) + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"]) + + def test_list_comprehension(self, testdir): + testdir.makepyfile( + """ + def check_even(num): + if num % 2 == 0: + return True + return False + + def test_list_comprehension(): + odd_list = list(range(1,9,2)) + assert all([check_even(num) for num in odd_list])""" + ) + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"]) + + def test_for_loop(self, testdir): + testdir.makepyfile( + """ + def check_even(num): + if num % 2 == 0: + return True + return False + + def test_for_loop(): + odd_list = list(range(1,9,2)) + for num in odd_list: + assert check_even(num) + """ + ) + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"]) + class TestRewriteOnImport(object): def test_pycache_is_a_file(self, testdir): From 043fdb7c4065e5eb54f3fb5776077bb8fd651ce6 Mon Sep 17 00:00:00 2001 From: danielx123 Date: Mon, 22 Apr 2019 18:23:51 -0400 Subject: [PATCH 2/3] 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 31c0da46d71..c826337ea50 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -9,6 +9,7 @@ import argparse import collections import platform +import subprocess import sys import time @@ -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 ) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index d0fdce23eb6..c1155b1e450 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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): From 4bfe88dea49fe27c96158b1bc3c6e6e2f0c55616 Mon Sep 17 00:00:00 2001 From: danielx123 Date: Mon, 22 Apr 2019 21:29:08 -0400 Subject: [PATCH 3/3] Fixed test case --- testing/test_terminal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index c1155b1e450..1e7c5ba55ad 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -285,7 +285,7 @@ def test_pass(num): assert 1 == 1""" ) result = testdir.runpytest() - result.stdout.fnmatch_lines(["*Package*", "*Version*"]) + result.stdout.fnmatch_lines(["*Package Version *"]) class TestCollectonly(object):