Skip to content

Commit 81138e5

Browse files
committed
Merge pull request pytest-dev#209 from blueyed/verbosity-with-dbsetup-and-flush
Pass on pytest.config.option.verbose to db setup / flush
2 parents 24a114f + 5bdb2f2 commit 81138e5

File tree

2 files changed

+56
-39
lines changed

2 files changed

+56
-39
lines changed

pytest_django/fixtures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def _django_db_setup(request,
5050
monkey_patch_creation_for_db_reuse()
5151

5252
# Create the database
53-
db_cfg = setup_databases(verbosity=0, interactive=False)
53+
db_cfg = setup_databases(verbosity=pytest.config.option.verbose,
54+
interactive=False)
5455

5556
def teardown_database():
5657
with _django_cursor_wrapper:
@@ -90,8 +91,8 @@ def flushdb():
9091
from django.core.management import call_command
9192

9293
for db in connections:
93-
call_command('flush', verbosity=0,
94-
interactive=False, database=db)
94+
call_command('flush', interactive=False, database=db,
95+
verbosity=pytest.config.option.verbose)
9596
for conn in connections.all():
9697
conn.close()
9798
request.addfinalizer(flushdb)

tests/test_environment.py

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,55 @@ def test_database_noaccess():
5050
Item.objects.count()
5151

5252

53-
def test_django_testrunner_verbosity_from_pytest(django_testdir):
54-
"""
55-
Test that Django's code to setup and teardown the databases uses pytest's
56-
verbosity level.
57-
"""
58-
django_testdir.create_test_module('''
59-
import pytest
60-
61-
@pytest.mark.django_db
62-
def test_inner_testrunner():
63-
pass
64-
''')
65-
66-
# Not verbose by default.
67-
result = django_testdir.runpytest('-s')
68-
result.stdout.fnmatch_lines([
69-
"tpkg/test_the_test.py ."])
70-
71-
# -v and -q results in verbosity 0.
72-
result = django_testdir.runpytest('-s', '-v', '-q')
73-
result.stdout.fnmatch_lines([
74-
"tpkg/test_the_test.py ."])
75-
76-
# Verbose output with '-v'.
77-
result = django_testdir.runpytest('-s', '-v')
78-
result.stdout.fnmatch_lines_random([
79-
"tpkg/test_the_test.py:*",
80-
"*PASSED*",
81-
"*Destroying test database for alias 'default'...*"])
82-
83-
# More verbose output with '-v -v'.
84-
result = django_testdir.runpytest('-s', '-v', '-v')
85-
result.stdout.fnmatch_lines_random([
86-
"tpkg/test_the_test.py:*",
87-
"*PASSED*",
88-
"*Destroying test database for alias 'default' ('*')...*"])
53+
class TestrunnerVerbosity:
54+
"""Test that Django's code to setup and teardown the databases uses
55+
pytest's verbosity level."""
56+
57+
@pytest.fixture
58+
def testdir(self, django_testdir):
59+
print("testdir")
60+
django_testdir.create_test_module('''
61+
import pytest
62+
63+
@pytest.mark.django_db
64+
def test_inner_testrunner():
65+
pass
66+
''')
67+
return django_testdir
68+
69+
def test_default(self, testdir):
70+
"""Not verbose by default."""
71+
result = testdir.runpytest('-s')
72+
result.stdout.fnmatch_lines([
73+
"tpkg/test_the_test.py ."])
74+
75+
def test_vq_verbosity_0(self, testdir):
76+
"""-v and -q results in verbosity 0."""
77+
result = testdir.runpytest('-s', '-v', '-q')
78+
result.stdout.fnmatch_lines([
79+
"tpkg/test_the_test.py ."])
80+
81+
def test_verbose_with_v(self, testdir):
82+
"""Verbose output with '-v'."""
83+
result = testdir.runpytest('-s', '-v')
84+
result.stdout.fnmatch_lines_random([
85+
"tpkg/test_the_test.py:*",
86+
"*PASSED*",
87+
"*Destroying test database for alias 'default'...*"])
88+
89+
def test_more_verbose_with_vv(self, testdir):
90+
"""More verbose output with '-v -v'."""
91+
result = testdir.runpytest('-s', '-v', '-v')
92+
result.stdout.fnmatch_lines([
93+
"tpkg/test_the_test.py:*Creating test database for alias*",
94+
"*Creating table app_item*",
95+
"*PASSED*Destroying test database for alias 'default' ('*')...*"])
96+
97+
def test_more_verbose_with_vv_and_reusedb(self, testdir):
98+
"""More verbose output with '-v -v', and --reuse-db."""
99+
result = testdir.runpytest('-s', '-v', '-v', '--reuse-db')
100+
result.stdout.fnmatch_lines([
101+
"tpkg/test_the_test.py:*Creating test database for alias*",
102+
"*PASSED*"])
103+
assert ("*Destroying test database for alias 'default' ('*')...*"
104+
not in result.stdout.str())

0 commit comments

Comments
 (0)