kitconcept / pytest-solr

Solr fixtures for Pytest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with connection

lw4z opened this issue · comments

commented

Hi, when I tried to run some problems occured:

my setup:

solr_process = solr_process(
  executable='downloads/solr-8.11.1/bin/solr',
  host='localhost',
  port=8983,
  # core='core_test',
  version='8.11.1',
  timeout=60
)

and I try to execute:


my_solr_core = solr_core(solr_process_fixture_name='solr_process', solr_core_name='core_test')
solr = solr('my_solr_core')

def test_exact_term_match(solr):
  solr.add([{'id': '1', 'title': 'bananas'}])
  assert 1 == solr.search('title:bananas').hits

returns:

venv/lib/python3.10/site-packages/pysolr.py:463: SolrError
------------------------------------------------------------------------------------ Captured log call ------------------------------------------------------------------------------------
ERROR    pysolr:pysolr.py:450 Solr responded with an error (HTTP 404): [Reason: Error 404 Not Found]
---------------------------------------------------------------------------------- Captured log teardown ----------------------------------------------------------------------------------
ERROR    pysolr:pysolr.py:450 Solr responded with an error (HTTP 404): [Reason: Error 404 Not Found]
======================================================================================== FAILURES =========================================================================================
__________________________________________________________________________________ test_exact_term_match __________________________________________________________________________________

solr = <pysolr.Solr object at 0x7fe3b069ef50>

    def test_exact_term_match(solr):
>     solr.add([{'id': '1', 'title': 'bananas'}])

solr_connection/test_solr_connection.py:21: 

Observation 1:

  • If set "solr_core_name" on my_solr_core and the core name is in solr_process solr, returns: "pysolr.SolrError: Solr responded with an error (HTTP 404): [Reason: Error 404 Not Found]" when executes test_exact_term_match. In this case, I remove "core='core_test'" from "solr_process" and set "solr_core_name" in my_solr_core and run.

Observation 2:

  • But for problem 1 not occures, in factories.py I changed the line and run:
process.get("host"), process.get("port"), solr_core_fixture_name 
process.get("host"), process.get("port"), "core_test"
  • I supose that this problem ocurres because the core name is not get from "solr_core_fixture_name", it's returning "my_solr_core"
  • solr_core_fixture_name is returning without core_name:
    {'host': 'localhost', 'port': 8983, 'version': '8.11.1', 'directory': 'downloads/solr-8.11.1', 'bin': 'downloads/solr-8.11.1/bin/solr', 'process': <Popen: returncode: None args: 'downloads/solr-8.11.1/bin/solr -f -p 8983'>}

I soulved changing:

def solr_core(solr_process_fixture_name, solr_core_name="default"):
    @pytest.fixture(scope="module")
    def solr_core_fixture(request):
        process = request.getfixturevalue(solr_process_fixture_name)
        solr_executable = process.get("bin")
        solr_core_directory = "tests/{}".format(solr_core_name)
        solr_port = str(process.get("port"))

to

def solr_core(solr_process_fixture_name):
    @pytest.fixture(scope="module")
    def solr_core_fixture(request):
        process = request.getfixturevalue(solr_process_fixture_name)
        solr_executable = process.get("bin")
        solr_core_directory = "tests/{}".format(process.get('core'))
        solr_port = str(process.get("port"))
        solr_core_name = "{}".format(process.get("core"))

and:

    def solr_process_fixture(request):
        solr = {
            "host": host,
            "port": port,
        }

to

    def solr_process_fixture(request):
        solr = {
            "host": host,
            "port": port,
            "core": core,
        }

for finally:

process.get("host"), process.get("port"), solr_core_fixture_name
to
process.get("host"), process.get("port"), process.get("core")

Sorry for the long description of the issue. I don't know if my solution is the better, but it's working for me now.