tox-dev / platformdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
https://platformdirs.readthedocs.io
MIT License
593 stars 51 forks source link

Testing could fail with pytest-randomly #184

Closed mtelka closed 1 year ago

mtelka commented 1 year ago

During testing of 3.5.1 I noticed that few tests sometimes fails when I test with the pytest-randomly plugin. Without the pytest-randomly plugin all tests always pass.

Here are typical failures:

_________________ test_method_result_is_path[user_runtime_dir] _________________

func_path = 'user_runtime_path'

    def test_method_result_is_path(func_path: str) -> None:
        method = getattr(platformdirs, func_path)
>       result = method()

tests/test_api.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py39/lib/python3.9/site-packages/platformdirs/__init__.py:526: in user_runtime_path
    return PlatformDirs(
.tox/py39/lib/python3.9/site-packages/platformdirs/api.py:209: in user_runtime_path
    return Path(self.user_runtime_dir)
.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:162: in user_runtime_dir
    path = f"/run/user/{getuid()}"
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def getuid() -> int:
>       raise RuntimeError("should only be used on Unix")
E       RuntimeError: should only be used on Unix

.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:13: RuntimeError
________________ test_property_result_is_path[user_runtime_dir] ________________

func_path = 'user_runtime_path'

    def test_property_result_is_path(func_path: str) -> None:
        dirs = platformdirs.PlatformDirs("MyApp", "MyCompany", version="1.0")
>       result = getattr(dirs, func_path)

tests/test_api.py:39:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py39/lib/python3.9/site-packages/platformdirs/api.py:209: in user_runtime_path
    return Path(self.user_runtime_dir)
.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:162: in user_runtime_dir
    path = f"/run/user/{getuid()}"
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def getuid() -> int:
>       raise RuntimeError("should only be used on Unix")
E       RuntimeError: should only be used on Unix

.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:13: RuntimeError
________________ test_property_result_is_str[user_runtime_dir] _________________

func = 'user_runtime_dir'

    def test_property_result_is_str(func: str) -> None:
        dirs = platformdirs.PlatformDirs("MyApp", "MyCompany", version="1.0")
>       result = getattr(dirs, func)

tests/test_api.py:27:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:162: in user_runtime_dir
    path = f"/run/user/{getuid()}"
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def getuid() -> int:
>       raise RuntimeError("should only be used on Unix")
E       RuntimeError: should only be used on Unix

.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:13: RuntimeError
_________________ test_method_result_is_str[user_runtime_dir] __________________

func = 'user_runtime_dir'

    def test_method_result_is_str(func: str) -> None:
        method = getattr(platformdirs, func)
>       result = method()

tests/test_api.py:21:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py39/lib/python3.9/site-packages/platformdirs/__init__.py:282: in user_runtime_dir
    return PlatformDirs(
.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:162: in user_runtime_dir
    path = f"/run/user/{getuid()}"
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def getuid() -> int:
>       raise RuntimeError("should only be used on Unix")
E       RuntimeError: should only be used on Unix

.tox/py39/lib/python3.9/site-packages/platformdirs/unix.py:13: RuntimeError
gaborbernat commented 1 year ago

We don't support running with that plugin. That being said feel free to add a PR to fix this.