napalm-automation / napalm-base

Apache License 2.0
32 stars 48 forks source link

Making testing configuration changes pytest compatible #234

Closed dbarrosop closed 7 years ago

dbarrosop commented 7 years ago

@luqasz would you care testing, please?

luqasz commented 7 years ago

You want me to test this commit with napalm-ros ?

dbarrosop commented 7 years ago

Yes, please. If I recall correctly you were having issues testing your load_replace code with our testing framework as it was broken.

luqasz commented 7 years ago
(napalm-ros)--- workspace/napalm-ros ‹config ?› » py.test test/unit/TestROSDriver.py -x                                   2 ↵
==================================================== test session starts =====================================================
platform darwin -- Python 2.7.13, pytest-3.0.6, py-1.4.32, pluggy-0.4.0 -- /Users/lkostka/.virtualenvs/napalm-ros/bin/python2.7
cachedir: .cache
rootdir: /Users/lkostka/workspace/napalm-ros, inifile: setup.cfg
plugins: pythonpath-0.7.1, json-0.4.0, cov-2.4.0, pylama-7.3.3
collected 42 items

test/unit/TestROSDriver.py::TestConfigNetworkDriver::test_replacing_and_committing_config <- napalm_base/test/base.py dupa
ERROR

--------------------------- generated json report: /Users/lkostka/workspace/napalm-ros/report.json ---------------------------

---------- coverage: platform darwin, python 2.7.13-final-0 ----------
Name                     Stmts   Miss  Cover
--------------------------------------------
napalm_ros/__init__.py       7      2    71%
napalm_ros/ros.py          154    112    27%
napalm_ros/utils.py         29     26    10%
--------------------------------------------
TOTAL                      190    140    26%

=========================================================== ERRORS ===========================================================
_______________________ ERROR at setup of TestConfigNetworkDriver.test_replacing_and_committing_config _______________________

cls = <class 'napalm_base.test.base.TestConfigNetworkDriver'>

    @classmethod
    def setup_class(cls):
        """Added for py.test/nosetests compatibility"""
        print('dupa')
>       cls.setUpClass()
E       AttributeError: type object 'TestConfigNetworkDriver' has no attribute 'setUpClass'

napalm_base/test/base.py:34: AttributeError

Still does not work.

dbarrosop commented 7 years ago

Your test class has to implement that method. For example:

https://github.com/napalm-automation/napalm-eos/blob/develop/test/unit/TestEOSDriver.py#L24

luqasz commented 7 years ago

It is implemented in https://github.com/napalm-automation/napalm-ros/blob/develop/test/unit/TestROSDriver.py#L9

dbarrosop commented 7 years ago

Ok, just noticed the problem, you are calling the file itself and that's calling the improted class. Call it like this:

py.test -vvv TestROSDriver.py::TestConfigROSDriver
luqasz commented 7 years ago

Now it works. Thx.