Skip to content

Commit

Permalink
Merge branch 'hotfix/0.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Jun 3, 2020
2 parents 0e1212b + 7852494 commit 1509a15
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
CHANGELOG
=========

0.5.4
-----

* Only enable pytest plugin when parasolr is in Django installed apps
and a Solr connection is configured

0.5.3
---

Expand Down
14 changes: 13 additions & 1 deletion parasolr/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

try:
import django
from django.apps import apps
from django.conf import settings
from django.test import override_settings
except ImportError:
Expand All @@ -25,7 +26,16 @@ def get_test_solr_config():
options specified are used; if no test collection name
is specified, generates one based on the configured collection.'''

# copy default config for basic connection optiosn (e.g. url)
# skip if parasolr is not actually in django installed apps
if not apps.is_installed("parasolr"):
return

# if no solr connection is configured, bail out
if not getattr(settings, 'SOLR_CONNECTIONS', None):
logger.warn('No Solr configuration found')
return

# copy default config for basic connection options (e.g. url)
test_config = settings.SOLR_CONNECTIONS['default'].copy()

# use test settings as primary: anything in test settings
Expand Down Expand Up @@ -67,6 +77,8 @@ def configure_django_test_solr():
"""

solr_config_opts = get_test_solr_config()
if not solr_config_opts:
return

logger.info('Configuring Solr for tests %(URL)s%(COLLECTION)s',
solr_config_opts)
Expand Down
32 changes: 30 additions & 2 deletions parasolr/tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Test pytest plugin fixture for django
"""
import uuid
from unittest.mock import patch

import pytest
try:
Expand Down Expand Up @@ -93,6 +93,34 @@ def test_solr_client():

# run all tests with pytest with all pytest-django plugins turned off
# result = testdir.runpytest('-p', 'no:django')
result = testdir.runpytest_subprocess('--capture', 'no') #, '-p', 'no:django')
result = testdir.runpytest_subprocess('--capture', 'no')
# check that test case passed
result.assert_outcomes(passed=1)


@skipif_no_django
def test_not_configured(testdir):
"""skip without error if not configured."""

with override_settings(SOLR_CONNECTIONS=None):
assert not get_test_solr_config()

# create a temporary pytest test file with no solr use
testdir.makepyfile("""
def test_unrelated():
assert 1 + 1 == 2
""")
# run all tests with pytest with all pytest-django plugins turned off
result = testdir.runpytest_subprocess('--capture', 'no')
# check that test case passed
result.assert_outcomes(passed=1)


@skipif_no_django
def test_app_not_installed(testdir):
"""skip without error if not configured."""

with patch('parasolr.pytest_plugin.apps') as mockapps:
mockapps.is_installed.return_value = False
assert not get_test_solr_config()
mockapps.is_installed.assert_called_with('parasolr')

0 comments on commit 1509a15

Please sign in to comment.