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

crash when a test changes the cwd to something that gets removed later on without propper cleanup #470

Closed
pytestbot opened this issue Feb 25, 2014 · 2 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Chris Warrick (BitBucket: Kwpolska, GitHub: Kwpolska)


I’m testing Nikola. I tried this file:

$ py.test tests/test_integration.py
============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- py-1.4.20 -- pytest-2.5.2
collected 53 items 

tests/test_integration.py .....................................................

========================== 53 passed in 97.54 seconds ==========================

Then I broke something. Specifically, commented out the building part.

============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- py-1.4.20 -- pytest-2.5.2
collected 53 items 

tests/test_integration.py FFFFFFFFFFFFFF.FFFFFFFF..FFF..FFF..FFFFFF$ echo $?
3

It just crashes. No idea why. I included the debug log, it says something to the effect of the CWD being inexistent.

Then I asked --verbose. It crashes at this:

tests/test_integration.py:108: RelativeLinkTest2.test_avoid_double_slash_in_rss

I tried to isolate it. Here’s the fun part: when I removed everything that was not this test case or what it inherited from, I got a build that actually finished:

============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- py-1.4.20 -- pytest-2.5.2 -- /home/kwpolska/virtualenvs/nikola-py2/bin/python2
collected 8 items 

tests/test_integration.py:80: EmptyBuildTest.test_build FAILED
tests/test_integration.py:108: DemoBuildTest.test_avoid_double_slash_in_rss FAILED                                                                              
tests/test_integration.py:80: DemoBuildTest.test_build FAILED
tests/test_integration.py:103: DemoBuildTest.test_index_in_sitemap FAILED
tests/test_integration.py:108: RelativeLinkTest2.test_avoid_double_slash_in_rss FAILED                                                                          
tests/test_integration.py:80: RelativeLinkTest2.test_build FAILED
tests/test_integration.py:147: RelativeLinkTest2.test_index_in_sitemap FAILED
tests/test_integration.py:133: RelativeLinkTest2.test_relative_links FAILED

=================================== FAILURES ===================================
…snip…
_______________ RelativeLinkTest2.test_avoid_double_slash_in_rss _______________

self = <tests.test_integration.RelativeLinkTest2 testMethod=test_avoid_double_slash_in_rss>

    def test_avoid_double_slash_in_rss(self):
        rss_path = os.path.join(self.target_dir, "output", "rss.xml")
>       rss_data = codecs.open(rss_path, "r", "utf8").read()

tests/test_integration.py:110: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

filename = '/tmp/tmpk9BlUY/target/output/rss.xml', mode = 'rb'
encoding = 'utf8', errors = 'strict', buffering = 1

    def open(filename, mode='rb', encoding=None, errors='strict', buffering=1):

        """ Open an encoded file using the given mode and return
            a wrapped version providing transparent encoding/decoding.

…snip…

        """
        if encoding is not None:
            if 'U' in mode:
                # No automatic conversion of '\n' is done on reading and writing
                mode = mode.strip().replace('U', '')
                if mode[:1] not in set('rwa'):
                    mode = 'r' + mode
            if 'b' not in mode:
                # Force opening of the file in binary mode
                mode = mode + 'b'
>       file = __builtin__.open(filename, mode, buffering)
E       IOError: [Errno 2] No such file or directory: u'/tmp/tmpk9BlUY/target/output/rss.xml'

../../virtualenvs/nikola-py2/lib/python2.7/codecs.py:881: IOError
…snip…
=========================== 8 failed in 0.51 seconds ===========================

What might be causing this?


@pytestbot
Copy link
Contributor Author

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


In the meanwhile you can add something like this to your conftest.py:

#!python

import os
import pytest

@pytest.yield_fixture(autouse=True)
def ensure_chdir():
    x = os.getcwd()
    yield
    os.chdir(x)

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@RonnyPfannschmidt
Copy link
Member

Closing as superseded by #1235

fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
* fix bracket match bug

* add missing test file
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

2 participants