最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

elasticsearch - Python subprocess not running inside pytest method - Stack Overflow

programmeradmin4浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论