Skip to content

Skip Django setup and manage.py scanning with "pytest --help" #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def pytest_load_initial_conftests(early_config, parser, args):

options = parser.parse_known_args(args)

if options.version or options.help:
return

django_find_project = _parse_django_find_project_ini(
early_config.getini('django_find_project'))

Expand Down Expand Up @@ -200,12 +203,6 @@ def pytest_load_initial_conftests(early_config, parser, args):
_setup_django()


@pytest.mark.trylast
def pytest_configure():
if django_settings_is_configured():
_setup_django()


def pytest_runtest_setup(item):

if django_settings_is_configured() and is_django_unittest(item):
Expand Down Expand Up @@ -234,6 +231,7 @@ def _django_test_environment(request):
we need to follow this model.
"""
if django_settings_is_configured():
_setup_django()
from django.conf import settings
from .compat import setup_test_environment, teardown_test_environment
settings.DEBUG = False
Expand Down
15 changes: 15 additions & 0 deletions tests/test_manage_py_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ def test_django_project_scan_disabled_invalid_settings(django_testdir,
result.stderr.fnmatch_lines(['*ImportError*DOES_NOT_EXIST*'])
result.stderr.fnmatch_lines(['*pytest-django did not search for '
'Django projects*'])


@pytest.mark.django_project(project_root='django_project_root',
create_manage_py=True)
def test_django_project_found_invalid_settings_version(django_testdir, monkeypatch):
"""Invalid DSM should not cause an error with --help or --version."""
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'DOES_NOT_EXIST')

result = django_testdir.runpytest('django_project_root', '--version')
assert result.ret == 0
result.stderr.fnmatch_lines(['*This is pytest version*'])

result = django_testdir.runpytest('django_project_root', '--help')
assert result.ret == 0
result.stdout.fnmatch_lines(['*usage:*'])