Pytest generates warnings when using testinfra wrapper
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 =========================================================```
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 ===========================```
Same problem here!
+1
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.
+1
Same Problem. Any updates?
@yife if you don't use '--nagios' option, use py.test command (instead of testinfra) to run the test suite.
I confirm the issue as well
I get this same issue, even when not running it with Molecule.
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
I confirm the issue as well
I can confirm the issue while running tests through Molecule.
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).