numirias / pytest-json-report

🗒️ A pytest plugin to report test results as JSON
MIT License
146 stars 39 forks source link

How to pass multiple fields to omit with direct invokation? #87

Closed mlondono74 closed 1 year ago

mlondono74 commented 1 year ago

Hello, thanks for the wonderful plugin...

from the cmd line this works as expected pytest test_trial.py --json-report --json-report-file=report.json --json-report-omit collectors keywords

doing the same with direct invokation works as expected

@app.get("/test/all")
async def runall_json():
    plugin = JSONReport()
    retcode = pytest.main([
                            "--json-report-file=report.json",
                            "--json-report-omit=keywords",
                            'test_trial.py'
                          ], plugins=[plugin])
    return plugin.report

but if I try to add more fields to omit, they ALL get ignored, for example

@app.get("/test/all")
async def runall_json():
    plugin = JSONReport()
    retcode = pytest.main([
                            "--json-report-file=report.json",
                            "--json-report-omit=keywords collectors",
                            'test_trial.py'
                          ], plugins=[plugin])
    return plugin.report

I have also tried various alternatives

"--json-report-omit=keywords,collectors"
"--json-report-omit=[keywords collectors]"
"--json-report-omit='keywords collectors' "
"--json-report-omit='keywords, collectors'"
"--json-report-omit keywords collectors'"

etc

What I am missing / doing wrong?

Thanks again

mlondono74 commented 1 year ago

This was user error on my part. Maybe looking at the issue will help others with a similar question. The correct way is with each arg value as a separate passed-in string. as shown below:

@app.get("/test/all")
async def runall_json():
    plugin = JSONReport()
    retcode = pytest.main([
                            "--json-report-file=report.json",
                            "--json-report-omit",
                            "keywords",
                            "collectors",
                            "test_trial.py"
                          ], plugins=[plugin])
    return plugin.report