Skip to content

test_cmdline_python_package() fails #74

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

Closed
pytestbot opened this issue Sep 25, 2011 · 10 comments
Closed

test_cmdline_python_package() fails #74

pytestbot opened this issue Sep 25, 2011 · 10 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Arfrever Frehtes Taifersar Arahesis (BitBucket: arfrever, GitHub: arfrever)


test_cmdline_python_package() from testing/acceptance_test.py fails at least with CPython 2.6 and 2.7. It passes with CPython 3.1 and 3.2.

$ py.test-2.7 testing/acceptance_test.py
==================================================================== test session starts ====================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.1.2
collected 38 items 

testing/acceptance_test.py ..................................F.x.

========================================================================= FAILURES ==========================================================================
____________________________________________________ TestInvocationVariants.test_cmdline_python_package _____________________________________________________

self = <acceptance_test.TestInvocationVariants instance at 0x2da3098>
testdir = <TmpTestdir local('/tmp/pytest-0/testdir/test_cmdline_python_package0/test_cmdline_python_package')>
monkeypatch = <_pytest.monkeypatch.monkeypatch instance at 0x2da3320>

    def test_cmdline_python_package(self, testdir, monkeypatch):
        monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', False)
        path = testdir.mkpydir("tpkg")
        path.join("test_hello.py").write("def test_hello(): pass")
        path.join("test_world.py").write("def test_world(): pass")
        result = testdir.runpytest("--pyargs", "tpkg")
        assert result.ret == 0
        result.stdout.fnmatch_lines([
            "*2 passed*"
        ])
        result = testdir.runpytest("--pyargs", "tpkg.test_hello")
        assert result.ret == 0
        result.stdout.fnmatch_lines([
            "*1 passed*"
        ])
        result = testdir.runpytest("--pyargs", ".")
        assert result.ret == 0
        result.stdout.fnmatch_lines([
>           "*2 passed*"
E           Failed: remains unmatched: '*2 passed*', see stderr

/tmp/pytest-2.1.2/testing/acceptance_test.py:409: Failed
---------------------------------------------------------------------- Captured stdout ----------------------------------------------------------------------
running ['/usr/bin/python2.7', '/usr/lib64/python2.7/site-packages/pytest.py', '--basetemp=/tmp/pytest-0/testdir/test_cmdline_python_package0/test_cmdline_python_package/runpytest-0', '--pyargs', 'tpkg'] curdir= /tmp/pytest-0/testdir/test_cmdline_python_package0/test_cmdline_python_package
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.1.2
collecting ... collected 2 items

tpkg/test_hello.py .
tpkg/test_world.py .

=========================== 2 passed in 0.02 seconds ===========================
running ['/usr/bin/python2.7', '/usr/lib64/python2.7/site-packages/pytest.py', '--basetemp=/tmp/pytest-0/testdir/test_cmdline_python_package0/test_cmdline_python_package/runpytest-1', '--pyargs', 'tpkg.test_hello'] curdir= /tmp/pytest-0/testdir/test_cmdline_python_package0/test_cmdline_python_package
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.1.2
collecting ... collected 1 items

tpkg/test_hello.py .

=========================== 1 passed in 0.01 seconds ===========================
running ['/usr/bin/python2.7', '/usr/lib64/python2.7/site-packages/pytest.py', '--basetemp=/tmp/pytest-0/testdir/test_cmdline_python_package0/test_cmdline_python_package/runpytest-2', '--pyargs', '.'] curdir= /tmp/pytest-0/testdir/test_cmdline_python_package0/test_cmdline_python_package
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.1.2
collecting ... collected 0 items

===============================  in 0.17 seconds ===============================
---------------------------------------------------------------------- Captured stderr ----------------------------------------------------------------------
nomatch: '*2 passed*'
    and: u'============================= test session starts =============================='
    and: u'platform linux2 -- Python 2.7.3 -- pytest-2.1.2'
    and: u'collecting ... collected 2 items'
    and: u''
    and: u'tpkg/test_hello.py .'
    and: u'tpkg/test_world.py .'
    and: u''
fnmatch: '*2 passed*'
   with: u'=========================== 2 passed in 0.02 seconds ==========================='
nomatch: '*1 passed*'
    and: u'============================= test session starts =============================='
    and: u'platform linux2 -- Python 2.7.3 -- pytest-2.1.2'
    and: u'collecting ... collected 1 items'
    and: u''
    and: u'tpkg/test_hello.py .'
    and: u''
fnmatch: '*1 passed*'
   with: u'=========================== 1 passed in 0.01 seconds ==========================='
nomatch: '*2 passed*'
    and: u'============================= test session starts =============================='
    and: u'platform linux2 -- Python 2.7.3 -- pytest-2.1.2'
    and: u'collecting ... collected 0 items'
    and: u''
    and: u'===============================  in 0.17 seconds ==============================='
====================================================== 1 failed, 36 passed, 1 xfailed in 53.20 seconds ======================================================

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


This neither fails in my develop laptop nor in the CI system, see e.g. http://hudson.testrun.org/view/pytest/job/pytest/TOXENV=py27,label=linux/352/console

so i wonder what the problem is. Could you try to track it down a bit more? And, failing that, provide more platform information?

@pytestbot
Copy link
Contributor Author

Original comment by Arfrever Frehtes Taifersar Arahesis (BitBucket: arfrever, GitHub: arfrever):


This patch fixes test failure for me:
{{{
--- testing/acceptance_test.py
+++ testing/acceptance_test.py
@@ -403,7 +403,7 @@
result.stdout.fnmatch_lines([
"1 passed"
])

  •    result = testdir.runpytest("--pyargs", ".")
    
  •    result = testdir.runpytest(".")
     assert result.ret == 0
     result.stdout.fnmatch_lines([
         "_2 passed_"
    
    }}}

The fact that this test failure hasn't occurred with CPython 3 might indicate that there is another bug.

@pytestbot
Copy link
Contributor Author

Original comment by Arfrever Frehtes Taifersar Arahesis (BitBucket: arfrever, GitHub: arfrever):


See differences in number of collected items:
{{{
$ mkdir /tmp/pytest_tests
$ cd /tmp/pytest_tests
$ echo 'def test(): pass' > test_something.py
$ py.test-2.7 .
==================================================================== test session starts ====================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.1.2
collected 1 items

test_something.py .

================================================================= 1 passed in 0.01 seconds ==================================================================
$ py.test-2.7 --pyargs .
==================================================================== test session starts ====================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.1.2
collected 0 items

===================================================================== in 0.17 seconds ======================================================================
$ py.test-3.2 .
==================================================================== test session starts ====================================================================
platform linux2 -- Python 3.2.3 -- pytest-2.1.2
collected 1 items

test_something.py .

================================================================= 1 passed in 0.02 seconds ==================================================================
$ py.test-3.2 --pyargs .
==================================================================== test session starts ====================================================================
platform linux2 -- Python 3.2.3 -- pytest-2.1.2
collected 1 items

test_something.py .

================================================================= 1 passed in 0.02 seconds ==================================================================
}}}

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


But this is about testing the "--pyargs" argument so removing it does not help. Like i said, for me this test passes everywhere and i'd like to understand why it fails on your machine.

@pytestbot
Copy link
Contributor Author

Original comment by Arfrever Frehtes Taifersar Arahesis (BitBucket: arfrever, GitHub: arfrever):


This problem occurs when there is a directory on sys.path and with init.py file.

{{{
$ mkdir /tmp/something
$ touch /tmp/something/init.py
$ PYTHONPATH="/tmp/something" py.test-2.7 testing/acceptance_test.py
...
}}}

_pytest.main.Session._tryconvertpyarg() maybe should more intelligently handle x==".". If x is ".", then x.split('.') returns ['', ''], so the loop iterates twice on the same string.

@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


i also fails for me, when running with pytest instead of tox

@pytestbot
Copy link
Contributor Author

Original comment by Arfrever Frehtes Taifersar Arahesis (BitBucket: arfrever, GitHub: arfrever):


New patch:
{{{
--- _pytest/main.py
+++ _pytest/main.py
@@ -470,8 +470,13 @@

 def _tryconvertpyarg(self, x):
     mod = None
  •    path = [os.path.abspath('.')] + sys.path
    
  •    for name in x.split('.'):
    
  •    if x == '.':
    
  •        path = [os.path.abspath('.')]
    
  •        names = ['']
    
  •    else:
    
  •        path = [os.path.abspath('.')] + sys.path
    
  •        names = x.split('.')
    
  •    for name in names:
         try:
             fd, mod, type_ = imp.find_module(name, path)
         except ImportError:
    
    }}}

@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


fix issue74 - propperly filter out missfit names in _tryconvertpyarg

@pytestbot
Copy link
Contributor Author

Original comment by Arfrever Frehtes Taifersar Arahesis (BitBucket: arfrever, GitHub: arfrever):


The test doesn't fail with previous code in _pytest/main.py.
{{{
--- testing/acceptance_test.py
+++ testing/acceptance_test.py
@@ -409,13 +409,14 @@
"2 passed"
])

  •    empty_package = testdir.mkpydir("empty_package")
    
  •    monkeypatch.setenv('PYTHONPATH', empty_package)
     result = testdir.runpytest("--pyargs", ".")
     assert result.ret == 0
     result.stdout.fnmatch_lines([
         "*2 passed*"
     ])
    
  •    monkeypatch.setenv('PYTHONPATH', testdir)
     path.join('test_hello.py').remove()
     result = testdir.runpytest("--pyargs", "tpkg.test_hello")
     assert result.ret != 0
    

    }}}

@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


tests fixed on current default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant