Search code examples
pytestpytest-html

How can I remove the "Environment" table from a Pytest-Html report


The following code I found on this website here does not have any effect.

It is suggested to set the metadata=None BUT this has no effect. Here is the code:

def pytest_configure(config):
    config._metadata = None

How can I remove the Environment table from the Pytest-Html report?

enter image description here


Solution

  • To delete the environment table:

    You need pytest-metadata plugin.

    from pytest_metadata.plugin import metadata_key
    
    
    def pytest_configure(config):
        config.stash[metadata_key]["foo"] = "bar"
    

    To hide entire environment section:

    You can use css, here is how:

    Create pytest.ini file and add:

    [pytest]
    
    addopts = --css=style.css
    

    Now create style.css and add:

    #environment-header,
    #environment {
      display: none;
    }