pytest-testinfra icon indicating copy to clipboard operation
pytest-testinfra copied to clipboard

Pytest generates warnings when using testinfra wrapper

Open electrickite opened this issue 10 years ago • 13 comments

Running a simple test with the testinfra wrapper generates a pytest warning in the console output. The tests pass/fail correctly and the command exits with a zero status code, but the warning is a little concerning. The warning is:

WP1 None Modules are already imported so can not be re-written: testinfra

Testinfra 1.42 Pytest 3.03 Python 2.7.12 macOS 10.12

$ cat mytest.py
def test_passwd_file(File):
    passwd = File("/etc/passwd")
    assert passwd.contains("root")
    assert passwd.user == "root"
    assert passwd.group == "wheel"
    assert passwd.mode == 0o644

(venv)
$ testinfra -v mytest.py
==================================================================== test session starts =====================================================================
platform darwin -- Python 2.7.12, pytest-3.0.3, py-1.4.31, pluggy-0.4.0 -- /Users/me/testing/venv/bin/python2.7
cachedir: .cache
rootdir: /Users/me/testing, inifile:
plugins: testinfra-1.4.2
collected 1 items

mytest.py::test_passwd_file[local] PASSED

=================================================================== pytest-warning summary ===================================================================
WP1 None Modules are already imported so can not be re-written: testinfra
======================================================== 1 passed, 1 pytest-warnings in 0.04 seconds =========================================================```

electrickite avatar Oct 12 '16 14:10 electrickite

Just a follow-up, running the tests via the pytest command works as expected:

(venv)
$ pytest -v mytest.py
============================= test session starts ==============================
platform darwin -- Python 2.7.12, pytest-3.0.3, py-1.4.31, pluggy-0.4.0 -- /Users/me/testing/venv/bin/python2.7
cachedir: .cache
rootdir: /Users/me/testing, inifile:
plugins: testinfra-1.4.2
collected 1 items

mytest.py::test_passwd_file[local] PASSED

=========================== 1 passed in 0.04 seconds ===========================```

electrickite avatar Oct 12 '16 18:10 electrickite

Same problem here!

emayssat-ms avatar Oct 15 '16 01:10 emayssat-ms

+1

xlvdk avatar Oct 21 '16 11:10 xlvdk

I think this should be resolved by moving the NagiosReporter code into a proper pytest plugin (thus testinfra become just an alias to pytest.main). I started to work on it, but not fully functional yet.

philpep avatar Oct 27 '16 21:10 philpep

+1

adeleglise avatar Nov 29 '16 09:11 adeleglise

Same Problem. Any updates?

yife avatar May 10 '17 13:05 yife

@yife if you don't use '--nagios' option, use py.test command (instead of testinfra) to run the test suite.

philpep avatar May 10 '17 15:05 philpep

I confirm the issue as well

elfgoh avatar Aug 06 '17 17:08 elfgoh

I get this same issue, even when not running it with Molecule.

wachpwnski avatar Aug 07 '17 07:08 wachpwnski

Running $ testinfra test_mac.py will duplicate the issue

def test_system_type(host):
    '''Check OS type'''
    assert host.system_info.type == "darwin"
    assert host.system_info.distribution == "Mac OS X"
======================== warnings summary =========================
None
  Module already imported so can not be re-written: testinfra

-- Docs: http://doc.pytest.org/en/latest/warnings.html

elfgoh avatar Aug 08 '17 12:08 elfgoh

I confirm the issue as well

gomex avatar Aug 15 '17 20:08 gomex

I can confirm the issue while running tests through Molecule.

lnovara avatar Aug 28 '17 13:08 lnovara

Hi, I finally get a fix in #253

TL;DR: Don't use testinfra command but use py.test command instead (unless combined with --nagios option, then wait for the patch to be released).

philpep avatar Sep 28 '17 18:09 philpep