Skip to content

Commit

Permalink
Show Django's version in the django report header
Browse files Browse the repository at this point in the history
Fix #987
  • Loading branch information
bluetech committed Oct 29, 2023
1 parent 721be6a commit d8be0ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ def pytest_configure() -> None:
@pytest.hookimpl()
def pytest_report_header(config: pytest.Config) -> Optional[List[str]]:
report_header = config.stash[report_header_key]

if "django" in sys.modules:
import django
report_header.insert(0, f"version: {django.get_version()}")

if report_header:
return ["django: " + ", ".join(report_header)]
return None
Expand Down
11 changes: 7 additions & 4 deletions tests/test_django_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def test_settings():
)
result = pytester.runpytest_subprocess()
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_env (from env), configuration: MySettings (from env)',
"django: version: *, settings: tpkg.settings_env (from env), "
"configuration: MySettings (from env)",
"* 1 passed*",
])
assert result.ret == 0
Expand Down Expand Up @@ -73,7 +74,8 @@ def test_ds():
)
result = pytester.runpytest_subprocess()
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_env (from env), configuration: MySettings (from env)',
"django: version: *, settings: tpkg.settings_env (from env), "
"configuration: MySettings (from env)",
"* 1 passed*",
])
assert result.ret == 0
Expand Down Expand Up @@ -103,7 +105,8 @@ def test_ds():
)
result = pytester.runpytest_subprocess()
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_ini (from ini), configuration: MySettings (from ini)',
"django: version: *, settings: tpkg.settings_ini (from ini), "
"configuration: MySettings (from ini)",
"* 1 passed*",
])
assert result.ret == 0
Expand Down Expand Up @@ -134,7 +137,7 @@ def test_ds():
)
result = pytester.runpytest_subprocess("--ds=tpkg.settings_opt", "--dc=MySettings")
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_opt (from option),'
'django: version: *, settings: tpkg.settings_opt (from option),'
' configuration: MySettings (from option)',
"* 1 passed*",
])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_django_settings_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_ds():
)
result = pytester.runpytest_subprocess()
result.stdout.fnmatch_lines([
"django: settings: tpkg.settings_ini (from ini)",
"django: version: *, settings: tpkg.settings_ini (from ini)",
"*= 1 passed*",
])
assert result.ret == 0
Expand All @@ -59,7 +59,7 @@ def test_settings():
)
result = pytester.runpytest_subprocess()
result.stdout.fnmatch_lines([
"django: settings: tpkg.settings_env (from env)",
"django: version: *, settings: tpkg.settings_env (from env)",
"*= 1 passed*",
])

Expand All @@ -85,7 +85,7 @@ def test_ds():
)
result = pytester.runpytest_subprocess("--ds=tpkg.settings_opt")
result.stdout.fnmatch_lines([
"django: settings: tpkg.settings_opt (from option)",
"django: version: *, settings: tpkg.settings_opt (from option)",
"*= 1 passed*",
])

Expand Down

0 comments on commit d8be0ef

Please sign in to comment.