Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testinfra (1.4.1) incompatible with py.test (3.0.2) (?) #125

Closed
Heiko-san opened this issue Sep 2, 2016 · 10 comments
Closed

testinfra (1.4.1) incompatible with py.test (3.0.2) (?) #125

Heiko-san opened this issue Sep 2, 2016 · 10 comments
Labels
bug This issue/PR relates to a bug.

Comments

@Heiko-san
Copy link

Heiko-san commented Sep 2, 2016

when upgrading to the latest version of testinfra with the lastest version of py.test (see above) it seems parametrization is broken:

def test_work(File):
    assert True

testinfra test.py

================================================================================================ test session starts ================================================================================================
platform linux2 -- Python 2.7.6, pytest-3.0.2, py-1.4.31, pluggy-0.3.1
rootdir: /, inifile: 
plugins: testinfra-1.4.1
collected 0 items / 1 errors 

====================================================================================================== ERRORS =======================================================================================================
_____________________________________________________________________________________________ ERROR collecting /test.py _____________________________________________________________________________________________
usr/local/lib/python2.7/dist-packages/testinfra/plugin.py:128: in pytest_generate_tests
    "_testinfra_backend", params, ids=ids, scope="module")
usr/local/lib/python2.7/dist-packages/_pytest/python.py:837: in parametrize
    raise ValueError(msg % (saferepr(id_value), type(id_value).__name__))
E   ValueError: ids must be list of strings, found: 'local' (type: unicode)
============================================================================================== pytest-warning summary ===============================================================================================
WP1 None Modules are already imported so can not be re-written: testinfra
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==================================================================================== 1 pytest-warnings, 1 error in 0.22 seconds =====================================================================================

when downgrading py.test to 3.0.1 everything works fine

when parameters are left away it will also work:

def test_work():
    assert True

we could reproduce the issue on the following os using native python (python2) with testrinfra installed via pip:

  • debian 7,8
  • ubuntu 1204,1404,1604
  • centos 5,6,7
  • sles 11.4,12.1
@philpep philpep added the bug This issue/PR relates to a bug. label Sep 2, 2016
@philpep
Copy link
Contributor

philpep commented Sep 2, 2016

Thanks for reporting.

Seems that pytest want bytes instead of unicode string, this patch should fix the issue

diff --git a/testinfra/plugin.py b/testinfra/plugin.py
index c177ea7..4da3446 100644
--- a/testinfra/plugin.py
+++ b/testinfra/plugin.py
@@ -123,7 +123,7 @@ def pytest_generate_tests(metafunc):
             sudo_user=metafunc.config.option.sudo_user,
             ansible_inventory=metafunc.config.option.ansible_inventory,
         )
-        ids = [e.get_pytest_id() for e in params]
+        ids = [e.get_pytest_id().encode() for e in params]
         metafunc.parametrize(
             "_testinfra_backend", params, ids=ids, scope="module")

@philpep
Copy link
Contributor

philpep commented Sep 2, 2016

Related to pytest-dev/pytest#1857

@philpep
Copy link
Contributor

philpep commented Sep 2, 2016

Opened pytest-dev/pytest#1905

@retr0h
Copy link
Contributor

retr0h commented Sep 2, 2016

@philpep Could we pin testinfra to a known working version of pytest? I ended up getting a bug report for this issue too, simply b/c molecule installs testinfra as a dependency. However, testinfra pulls the most current version of pytest.

Could we pin to a known good working version of pytest, this way, when we install a particular version of pytest, it's known to have been tested against locked deps?

philpep added a commit that referenced this issue Sep 3, 2016
@philpep
Copy link
Contributor

philpep commented Sep 3, 2016

@retr0h agree, was planned but I forget and was afk for some time, I release a fix ASAP.

This will be fixed in pytest 3.0.3 btw

@philpep
Copy link
Contributor

philpep commented Sep 3, 2016

Fixed in 1.4.2

@retr0h
Copy link
Contributor

retr0h commented Sep 3, 2016

@philpep Would it make more sense to simply pin to 3.0.2? What if we run into another incompatibility issue with a future pytest release. #126 doesn't really guard against that.

@philpep
Copy link
Contributor

philpep commented Sep 3, 2016

@retr0h (you mean 3.0.1 ?) I prefer to not pin exactly to a specific version, for several reasons (security, consistency of the whole dependency graph). But it could surely add something like pytest>=$first_working_version,<$next_untested_major_version.YY,!=$blaklist_version

@retr0h
Copy link
Contributor

retr0h commented Sep 3, 2016

I am fine with what you did. Mostly was hoping to prevent breakage in the future. However, I get your points.

@philpep
Copy link
Contributor

philpep commented Sep 3, 2016

But except this one, regressions are very rare with pytest and they have deprecation warnings, so I think it's also ok to not pin pytest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants