1
votes

I have created a project in eclipse using pytest framework

class TestClass(object):
    def test_one(self):
        x = "this"
        assert 'h' in x

    def test_two(self):
        x = "hello"
        assert hasattr(x, 'check')

Now, I want to create a html report for my project.I have done the following:

  • Installed the html plugin
  • Written the below code in conftest.py module
import pytest

@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    pytest_html = item.config.pluginmanager.getplugin('html')
    outcome = yield
    report = outcome.get_result()

When I ran my test, I didn't get any report.Below is my result as expected, but no report got generated

> ============================= test session starts ============================= platform win32 -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0 rootdir: D:\Eclipse1\TFCProject,
> inifile: plugins: ordering-0.5, metadata-1.7.0, html-1.19.0 collected
> 2 items
> 
> TFCPackage\pycheck.py .F                                              
> [100%]
> 
> ================================== FAILURES ===================================
> _____________________________ TestClass.test_two self = <TFCPackage.pycheck.TestClass object at 0x03778AF0>

    def test_two(self):
        x = "hello"
>       assert hasattr(x, 'check')
E       AssertionError: assert False
E        +  where False = hasattr('hello', 'check')

TFCPackage\pycheck.py:13: AssertionError
===================== 1 failed, 1 passed in 0.41 seconds ======================

Please guide me as I am new to pytest

1
pytest --html=report.html?hoefling

1 Answers

1
votes

If you want to do it in Eclipse IDE, you need to change your Eclipse Configuration.

  1. Open the Configuration

    Window -> Preferences -> PyDev -> PyUnit

  2. Add this parameter in the section "Parameters for test runner"

    --html= reportname.html

Replace reportname above with the name of your choice for report.

Please note that this setting is global and report will be generated every time you run pytest in eclipse.