Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request pytest-dev#238 from blueyed/no-error-for-help-and-…
Browse files Browse the repository at this point in the history
…version

Skip Django setup and manage.py scanning with "pytest --help". Thanks @blueyed
  • Loading branch information
pelme committed Jul 25, 2015
2 parents adedb06 + 61372a2 commit fe7d280
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pytest_django/plugin.py
Expand Up @@ -171,6 +171,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 @@ -217,12 +220,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 @@ -251,6 +248,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
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:*'])

0 comments on commit fe7d280

Please sign in to comment.