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

resolve manually set basetemp to a absolute path #4425

Closed
r2dan opened this Issue Nov 20, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@r2dan

r2dan commented Nov 20, 2018

Hi Guys,

We're experiencing some issues with new tmpdir implementation using pathlib. Starting from pytest 3.9.0 our tests started to fail.

We are using test class and a pre_process fixture, which prepares some data for the other tests within the class. In the test methods we're using the pre_process fixture (to access the data) as well as the tmpdir pytest builtin fixture to store some outcomes of the tests. Minimal failing example is pasted below:

import pytest, os

class TestDummy():
    @pytest.fixture(scope="class")
    def pre_process(self, tmpdir_factory):
        path_with_data = tmpdir_factory.mktemp('data')
        return path_with_data

    @pytest.mark.parametrize("param", range(2))
    def test_dummy(self, tmpdir, pre_process, param):
        os.chdir(pre_process)
        # further processing

    def test_dummy2(self, tmpdir, pre_process):
        os.chdir(pre_process)
        # further processing

Because of the directory change in test_dummy, next invocation of the tests fail due to pathlib error, as below:


self = PosixPath('tmp')

    def iterdir(self):
        """Iterate over the files in this directory.  Does not yield any
        result for the special paths '.' and '..'.
        """
        if self._closed:
            self._raise_closed()
>       for name in self._accessor.listdir(self):

../../../.pyenv/versions/3.6.5/lib/python3.6/pathlib.py:1079: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

pathobj = PosixPath('tmp'), args = ()

    @functools.wraps(strfunc)
    def wrapped(pathobj, *args):
>       return strfunc(str(pathobj), *args)
E       FileNotFoundError: [Errno 2] No such file or directory: 'tmp'

../../../.pyenv/versions/3.6.5/lib/python3.6/pathlib.py:387: FileNotFoundError

and in fact we end up with 1 pass and 2 errors in this particular case.

We currently have workaround for this issue (store the cwd before changing it and restore it before the test end), but I'd like to ask you if this is how it should behave? I'd expect that state of one test does not influence the other test's state.

The issue is observable if no class hierarchy is used as well.

Another workaround (a little bit nasty) is to reset internal pytest variable in pre_process macro:

def pre_process(tmpdir_factory):
    path_with_data = tmpdir_factory.mktemp('data')
    tmpdir_factory._tmppath_factory._basetemp = None
    return path_with_data```

Environment details:
Python 3.6.5 (via pyenv), 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:37:27 UTC 2018 i686 i686 i686 GNU/Linux

$ pip list
Package Version


atomicwrites 1.2.1
attrs 18.2.0
more-itertools 4.3.0
pip 18.1
pluggy 0.8.0
py 1.7.0
pytest 4.0.0
setuptools 40.6.2
six 1.11.0 ```

  • Include a detailed description of the bug or suggestion
  • pip list of the virtual environment you are using:
  • pytest and operating system versions:
  • Minimal example if possible - already in the text
@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Nov 20, 2018

please paste the full traceback, the cut version lacks the context needed to get any idea whats happening

@r2dan

This comment has been minimized.

r2dan commented Nov 20, 2018

Sure:

$ pytest test.py 
=============================================================================================================== test session starts ================================================================================================================
platform linux -- Python 3.6.5, pytest-4.0.0, py-1.7.0, pluggy-0.8.0
rootdir: /home/mrusi, inifile: pytest.ini
collected 3 items                                                                                                                                                                                                                                  

test.py .EE                                                                                                                                                                                                                                  [100%]

====================================================================================================================== ERRORS ======================================================================================================================
____________________________________________________________________________________________________ ERROR at setup of TestDummy.test_dummy[1] _____________________________________________________________________________________________________

self = PosixPath('tmp')

    def iterdir(self):
        """Iterate over the files in this directory.  Does not yield any
        result for the special paths '.' and '..'.
        """
        if self._closed:
            self._raise_closed()
>       for name in self._accessor.listdir(self):

../../../.pyenv/versions/3.6.5/lib/python3.6/pathlib.py:1079: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

pathobj = PosixPath('tmp'), args = ()

    @functools.wraps(strfunc)
    def wrapped(pathobj, *args):
>       return strfunc(str(pathobj), *args)
E       FileNotFoundError: [Errno 2] No such file or directory: 'tmp'

../../../.pyenv/versions/3.6.5/lib/python3.6/pathlib.py:387: FileNotFoundError
_____________________________________________________________________________________________________ ERROR at setup of TestDummy.test_dummy2 ______________________________________________________________________________________________________

self = PosixPath('tmp')

    def iterdir(self):
        """Iterate over the files in this directory.  Does not yield any
        result for the special paths '.' and '..'.
        """
        if self._closed:
            self._raise_closed()
>       for name in self._accessor.listdir(self):

../../../.pyenv/versions/3.6.5/lib/python3.6/pathlib.py:1079: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

pathobj = PosixPath('tmp'), args = ()

    @functools.wraps(strfunc)
    def wrapped(pathobj, *args):
>       return strfunc(str(pathobj), *args)
E       FileNotFoundError: [Errno 2] No such file or directory: 'tmp'

../../../.pyenv/versions/3.6.5/lib/python3.6/pathlib.py:387: FileNotFoundError
================================================================================================================= warnings summary =================================================================================================================
/home/mrusi/.pyenv/versions/3.6.5/lib/python3.6/site-packages/_pytest/resultlog.py:39
  /home/mrusi/.pyenv/versions/3.6.5/lib/python3.6/site-packages/_pytest/resultlog.py:39: RemovedInPytest4Warning: --result-log is deprecated and scheduled for removal in pytest 4.0.
  See https://docs.pytest.org/en/latest/usage.html#creating-resultlog-format-files for more information.
    _issue_config_warning(RESULT_LOG, config)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================================================================== 1 passed, 1 warnings, 2 error in 0.09 seconds ===================================================================================================

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Nov 20, 2018

it seems the normal output is not enough (this is a case where pytest removing pytest from the traceback actually makes things worse)

please take a look if the traceback given by pytest test.py --fulltrace gives more insight

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Nov 20, 2018

also a sidenote - i'm testing with pytest 4 myself and i don't see an issue on my system, so we might be looking at a environmental/hard to replicate issue

since the "temporary directory" that seems to be used in your example is a relative path, i do wonder if it might be a miss-configured environment and if/how we should warn

@r2dan

This comment has been minimized.

r2dan commented Nov 20, 2018

Sorry for a confusion! I was using custom config in pytest.ini, setting the basetemp to relative path, like this: pytest --basetemp=./tmp test.py

Full stack trace below:
full_trace.txt

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Nov 20, 2018

i see - that's a unintended behavior difference then and must be resolved by making the temporary folder absolute

the new code doesn't resolve the path to its final absolute value - and it should

thanks for reporting

@RonnyPfannschmidt RonnyPfannschmidt changed the title from FileNotFoundError: [Errno 2] No such file or directory: 'tmp' in specific fixture setup - appeared after pytest 'tmpdir' migration to 'pathlib' to resolve manually set basetemp to a absolute path Nov 20, 2018

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Nov 20, 2018

Just to add that you can use monkeypatch.chdir to change directories safely inside tests.

peterbe added a commit to mozilla-services/tecken that referenced this issue Nov 26, 2018

Update pytest to 4.0.1 (#1359)
This PR updates [pytest](https://pypi.org/project/pytest) from **4.0.0** to **4.0.1**.



<details>
  <summary>Changelog</summary>
  
  
   ### 4.0.1
   ```
   =========================

Bug Fixes
---------

- `3952 &lt;https://github.com/pytest-dev/pytest/issues/3952&gt;`_: Display warnings before &quot;short test summary info&quot; again, but still later warnings in the end.


- `4386 &lt;https://github.com/pytest-dev/pytest/issues/4386&gt;`_: Handle uninitialized exceptioninfo in repr/str.


- `4393 &lt;https://github.com/pytest-dev/pytest/issues/4393&gt;`_: Do not create ``.gitignore``/``README.md`` files in existing cache directories.


- `4400 &lt;https://github.com/pytest-dev/pytest/issues/4400&gt;`_: Rearrange warning handling for the yield test errors so the opt-out in 4.0.x correctly works.


- `4405 &lt;https://github.com/pytest-dev/pytest/issues/4405&gt;`_: Fix collection of testpaths with ``--pyargs``.


- `4412 &lt;https://github.com/pytest-dev/pytest/issues/4412&gt;`_: Fix assertion rewriting involving ``Starred`` + side-effects.


- `4425 &lt;https://github.com/pytest-dev/pytest/issues/4425&gt;`_: Ensure we resolve the absolute path when the given ``--basetemp`` is a relative path.



Trivial/Internal Changes
------------------------

- `4315 &lt;https://github.com/pytest-dev/pytest/issues/4315&gt;`_: Use ``pkg_resources.parse_version`` instead of ``LooseVersion`` in minversion check.


- `4440 &lt;https://github.com/pytest-dev/pytest/issues/4440&gt;`_: Adjust the stack level of some internal pytest warnings.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>

bors bot added a commit to mozilla/normandy that referenced this issue Nov 26, 2018

Merge #1629
1629: Scheduled weekly dependency update for week 47 r=mythmon a=pyup-bot






### Update [botocore](https://pypi.org/project/botocore) from **1.12.47** to **1.12.51**.


<details>
  <summary>Changelog</summary>
  
  
   ### 1.12.51
   ```
   =======

* api-change:``amplify``: Update amplify client to latest version
* api-change:``transfer``: Update transfer client to latest version
* api-change:``snowball``: Update snowball client to latest version
* api-change:``robomaker``: Update robomaker client to latest version
* api-change:``s3``: Update s3 client to latest version
* api-change:``datasync``: Update datasync client to latest version
   ```
   
  
  
   ### 1.12.50
   ```
   =======

* api-change:``rekognition``: Update rekognition client to latest version
   ```
   
  
  
   ### 1.12.49
   ```
   =======

* api-change:``autoscaling-plans``: Update autoscaling-plans client to latest version
* api-change:``xray``: Update xray client to latest version
* api-change:``devicefarm``: Update devicefarm client to latest version
* api-change:``ssm``: Update ssm client to latest version
* api-change:``medialive``: Update medialive client to latest version
* api-change:``redshift``: Update redshift client to latest version
* api-change:``rds-data``: Update rds-data client to latest version
* api-change:``appsync``: Update appsync client to latest version
* api-change:``cloudwatch``: Update cloudwatch client to latest version
* api-change:``quicksight``: Update quicksight client to latest version
* api-change:``cloudfront``: Update cloudfront client to latest version
   ```
   
  
  
   ### 1.12.48
   ```
   =======

* api-change:``lightsail``: Update lightsail client to latest version
* api-change:``workspaces``: Update workspaces client to latest version
* api-change:``workdocs``: Update workdocs client to latest version
* api-change:``batch``: Update batch client to latest version
* api-change:``ec2``: Update ec2 client to latest version
* api-change:``devicefarm``: Update devicefarm client to latest version
* api-change:``rds``: Update rds client to latest version
* api-change:``cloudformation``: Update cloudformation client to latest version
* api-change:``lambda``: Update lambda client to latest version
* api-change:``config``: Update config client to latest version
* api-change:``cloudtrail``: Update cloudtrail client to latest version
* api-change:``mediaconvert``: Update mediaconvert client to latest version
* api-change:``iot``: Update iot client to latest version
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/botocore
  - Changelog: https://pyup.io/changelogs/botocore/
  - Repo: https://github.com/boto/botocore
</details>





### Update [Pygments](https://pypi.org/project/Pygments) from **2.2.0** to **2.3.0**.


<details>
  <summary>Changelog</summary>
  
  
   ### 2.3.0
   ```
   -------------
(released Nov 25, 2018)

- Added lexers:

  * Fennel (PR783)
  * HLSL (PR675)

- Updated lexers:

  * Dockerfile (PR714)

- Minimum Python versions changed to 2.7 and 3.5
- Added support for Python 3.7 generator changes (PR772)
- Fix incorrect token type in SCSS for single-quote strings (1322)
- Use `terminal256` formatter if `TERM` contains `256` (PR666)
- Fix incorrect handling of GitHub style fences in Markdown (PR741, 1389)
- Fix `%a` not being highlighted in Python3 strings (PR727)
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pygments
  - Changelog: https://pyup.io/changelogs/pygments/
  - Homepage: http://pygments.org/
</details>





### Update [boto3](https://pypi.org/project/boto3) from **1.9.47** to **1.9.51**.


<details>
  <summary>Changelog</summary>
  
  
   ### 1.9.51
   ```
   ======

* api-change:``amplify``: [``botocore``] Update amplify client to latest version
* api-change:``transfer``: [``botocore``] Update transfer client to latest version
* api-change:``snowball``: [``botocore``] Update snowball client to latest version
* api-change:``robomaker``: [``botocore``] Update robomaker client to latest version
* api-change:``s3``: [``botocore``] Update s3 client to latest version
* api-change:``datasync``: [``botocore``] Update datasync client to latest version
   ```
   
  
  
   ### 1.9.50
   ```
   ======

* api-change:``rekognition``: [``botocore``] Update rekognition client to latest version
   ```
   
  
  
   ### 1.9.49
   ```
   ======

* api-change:``autoscaling-plans``: [``botocore``] Update autoscaling-plans client to latest version
* api-change:``xray``: [``botocore``] Update xray client to latest version
* api-change:``devicefarm``: [``botocore``] Update devicefarm client to latest version
* api-change:``ssm``: [``botocore``] Update ssm client to latest version
* api-change:``medialive``: [``botocore``] Update medialive client to latest version
* api-change:``redshift``: [``botocore``] Update redshift client to latest version
* api-change:``rds-data``: [``botocore``] Update rds-data client to latest version
* api-change:``appsync``: [``botocore``] Update appsync client to latest version
* api-change:``cloudwatch``: [``botocore``] Update cloudwatch client to latest version
* api-change:``quicksight``: [``botocore``] Update quicksight client to latest version
* api-change:``cloudfront``: [``botocore``] Update cloudfront client to latest version
   ```
   
  
  
   ### 1.9.48
   ```
   ======

* api-change:``lightsail``: [``botocore``] Update lightsail client to latest version
* api-change:``workspaces``: [``botocore``] Update workspaces client to latest version
* api-change:``workdocs``: [``botocore``] Update workdocs client to latest version
* api-change:``batch``: [``botocore``] Update batch client to latest version
* api-change:``ec2``: [``botocore``] Update ec2 client to latest version
* api-change:``devicefarm``: [``botocore``] Update devicefarm client to latest version
* api-change:``rds``: [``botocore``] Update rds client to latest version
* api-change:``cloudformation``: [``botocore``] Update cloudformation client to latest version
* api-change:``lambda``: [``botocore``] Update lambda client to latest version
* api-change:``config``: [``botocore``] Update config client to latest version
* api-change:``cloudtrail``: [``botocore``] Update cloudtrail client to latest version
* api-change:``mediaconvert``: [``botocore``] Update mediaconvert client to latest version
* api-change:``iot``: [``botocore``] Update iot client to latest version
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/boto3
  - Changelog: https://pyup.io/changelogs/boto3/
  - Repo: https://github.com/boto/boto3
</details>





### Update [pytest](https://pypi.org/project/pytest) from **4.0.0** to **4.0.1**.


<details>
  <summary>Changelog</summary>
  
  
   ### 4.0.1
   ```
   =========================

Bug Fixes
---------

- `3952 &lt;https://github.com/pytest-dev/pytest/issues/3952&gt;`_: Display warnings before &quot;short test summary info&quot; again, but still later warnings in the end.


- `4386 &lt;https://github.com/pytest-dev/pytest/issues/4386&gt;`_: Handle uninitialized exceptioninfo in repr/str.


- `4393 &lt;https://github.com/pytest-dev/pytest/issues/4393&gt;`_: Do not create ``.gitignore``/``README.md`` files in existing cache directories.


- `4400 &lt;https://github.com/pytest-dev/pytest/issues/4400&gt;`_: Rearrange warning handling for the yield test errors so the opt-out in 4.0.x correctly works.


- `4405 &lt;https://github.com/pytest-dev/pytest/issues/4405&gt;`_: Fix collection of testpaths with ``--pyargs``.


- `4412 &lt;https://github.com/pytest-dev/pytest/issues/4412&gt;`_: Fix assertion rewriting involving ``Starred`` + side-effects.


- `4425 &lt;https://github.com/pytest-dev/pytest/issues/4425&gt;`_: Ensure we resolve the absolute path when the given ``--basetemp`` is a relative path.



Trivial/Internal Changes
------------------------

- `4315 &lt;https://github.com/pytest-dev/pytest/issues/4315&gt;`_: Use ``pkg_resources.parse_version`` instead of ``LooseVersion`` in minversion check.


- `4440 &lt;https://github.com/pytest-dev/pytest/issues/4440&gt;`_: Adjust the stack level of some internal pytest warnings.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>





### Update [whitenoise](https://pypi.org/project/whitenoise) from **4.1.1** to **4.1.2**.


<details>
  <summary>Changelog</summary>
  
  
   ### 4.1.2
   ```
   ------

 * Add correct MIME type for WebAssembly, which is required for files to be
   executed (thanks `mdboom &lt;https://github.com/mdboom&gt;`_ ).
 * Stop accessing the FILE_CHARSET Django setting which was almost entirely
   unused and is now deprecated (thanks `timgraham
   &lt;https://github.com/timgraham&gt;`_).
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/whitenoise
  - Changelog: https://pyup.io/changelogs/whitenoise/
  - Homepage: http://whitenoise.evans.io
</details>





### Update [backoff](https://pypi.org/project/backoff) from **1.6.0** to **1.7.0**.


<details>
  <summary>Changelog</summary>
  
  
   ### 1.7.0
   ```
   Changed

- Support Python 3.7
- Drop support for async in Python 3.4
- Drop support for Python 2.6
- Update development dependencies
- Use poetry for dependencies and packaging
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/backoff
  - Changelog: https://pyup.io/changelogs/backoff/
  - Repo: https://github.com/litl/backoff
</details>







Co-authored-by: pyup-bot <github-bot@pyup.io>

bors bot added a commit to rehandalal/therapist that referenced this issue Nov 27, 2018

Merge #47
47: Update pytest to 4.0.1 r=rehandalal a=pyup-bot


This PR updates [pytest](https://pypi.org/project/pytest) from **4.0.0** to **4.0.1**.



<details>
  <summary>Changelog</summary>
  
  
   ### 4.0.1
   ```
   =========================

Bug Fixes
---------

- `3952 &lt;https://github.com/pytest-dev/pytest/issues/3952&gt;`_: Display warnings before &quot;short test summary info&quot; again, but still later warnings in the end.


- `4386 &lt;https://github.com/pytest-dev/pytest/issues/4386&gt;`_: Handle uninitialized exceptioninfo in repr/str.


- `4393 &lt;https://github.com/pytest-dev/pytest/issues/4393&gt;`_: Do not create ``.gitignore``/``README.md`` files in existing cache directories.


- `4400 &lt;https://github.com/pytest-dev/pytest/issues/4400&gt;`_: Rearrange warning handling for the yield test errors so the opt-out in 4.0.x correctly works.


- `4405 &lt;https://github.com/pytest-dev/pytest/issues/4405&gt;`_: Fix collection of testpaths with ``--pyargs``.


- `4412 &lt;https://github.com/pytest-dev/pytest/issues/4412&gt;`_: Fix assertion rewriting involving ``Starred`` + side-effects.


- `4425 &lt;https://github.com/pytest-dev/pytest/issues/4425&gt;`_: Ensure we resolve the absolute path when the given ``--basetemp`` is a relative path.



Trivial/Internal Changes
------------------------

- `4315 &lt;https://github.com/pytest-dev/pytest/issues/4315&gt;`_: Use ``pkg_resources.parse_version`` instead of ``LooseVersion`` in minversion check.


- `4440 &lt;https://github.com/pytest-dev/pytest/issues/4440&gt;`_: Adjust the stack level of some internal pytest warnings.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>



Co-authored-by: pyup-bot <github-bot@pyup.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment