pytest-dev / pytest-dev/pytest-html

The "create report" option, --html's parameter should be optional as it's possible to specify the name procedurally

Open
#477 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

next-gen
Dominant language
Python
Stars
779
Forks
260
PR merge metrics
No merged PRs in 30d

Description

When one sets the report name procedurally, eg:

@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
    """
    Runs early, report name must be set here
    https://stackoverflow.com/questions/60571675/setting-dynamic-folder-and-report-name-in-pytest
    :param config:
    :return:
    """
    env = os.environ['ENVIRONMENT']
    assert env is not None
    now = datetime.now()
    # create report target dir
    reports_dir = Path('reports')
    reports_dir.mkdir(parents=True, exist_ok=True)
    # custom report file
    report = reports_dir / f"{env}_{now.strftime('%Y-%m-%d_%H-%M')}.html"
    config.option.htmlpath = report.absolute()

The is no need to have a parameter to the --html arg as it's being specified in the code above.

However, one currently still needs to provide this to satisfy the argparser:

[I] ➜ py.test  .... --html
ERROR: usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: argument --html: expected one argument

It forces one to specify a parameter, eg: --html=xx solely for the parser validation.

In short, please make the --html arg's parameter optional.

thanks

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the pytest-html command-line option definition and the pytest_configure hook behavior described in the issue. Verify that --html can be used without a value when the report path is assigned procedurally, while existing explicit paths continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.