admin管理员组

文章数量:1241124

Initially, I have this code to connect to an Elasticsearch artifact and upload the initial documents to it. This part works well, and the index those documents are in exist and the documents exist as well. These all use @Given and @And from pytest.

However the next part is to run a custom command which originates from another file, and the command was made using typer. This part uses the @When from pytest. So it’s like “When the command is run a new index is created which consists of documents where the name files are similar and those with similar names joined into one document”. Then the next and last method uses the @Then and is supposed to get from the newly created index for matching pairs and compare against an expected_output.json. Haven’t even gotten here though because the new index isn’t been being created by the custom command. It’s something like this:

@When(custom command is run, pairs are generated)
def run_command():
   os.environ[elastic_env] = local
   subprocess.run(command.split(“ “))#Goes through a bunch of methods to create the new index and generate the pair documents to put in it

@Then(“documents from new index match the ones in expected output file”)
def check_against_output(context):
    client = context[‘es_client’] #context from another pytest fixture
    
     output = client.indices.search(index = “new_index”, query = “match all {}”)

But the subprocess doesn’t throw an error, so it just runs the command but does nothing, so the index never gets created, so I get a no index found exception in check_against_output. Any ideas for why the subprocess isn’t working? I tried changing Elasticsearch instance scope to modular, and I tried using os.system as well. Works in the terminal and Python shell. I’m in WSL using Ubuntu:22.04. Any help is appreciated, thank you.

本文标签: elasticsearchPython subprocess not running inside pytest methodStack Overflow