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

tmpdir path too long on macOS #5802

Closed
adamjstewart opened this issue Aug 29, 2019 · 13 comments
Closed

tmpdir path too long on macOS #5802

adamjstewart opened this issue Aug 29, 2019 · 13 comments

Comments

@adamjstewart
Copy link
Contributor

adamjstewart commented Aug 29, 2019

I have a unit test that runs gpg. First we set GNUPGHOME to the temporary directory that pytest creates, then we run it using our own keys. However, gpg fails with the following error:

gpg: keybox '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/pytest-of-Adam/pytest-5/test_buildcache0/gpg/pubring.kbx' created
gpg: can't connect to the agent: File name too long
gpg: agent_genkey failed: No agent running
gpg: key generation failed: No agent running

According to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=847206, gpg cannot handle long paths. Is there any way to shorten /private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/pytest-of-Adam/pytest-5/test_buildcache0/gpg/pubring.kbx?

platform darwin -- Python 3.7.3, pytest-3.2.5, py-1.4.34, pluggy-0.4.0

Possibly related to #291

@adamjstewart
Copy link
Contributor Author

Hmm, didn't realize I was using such an ancient version of pytest. It looks like 3.2.5 is the last version that supports Python 2.6. I assume this bug has been fixed in newer versions of pytest, so I'll close this unless I find a way to reproduce it.

@adamjstewart
Copy link
Contributor Author

Hmm, but #291 was claimed to be fixed long before pytest 3.2.5. Reopening...

@adamjstewart adamjstewart reopened this Aug 29, 2019
@RonnyPfannschmidt
Copy link
Member

indeed, thats a different issue (full path vs path component)

as a workaround you can probably use --basetemp and manage the creation/destruction/naming of the tmpdir (pytest will reset the content of the given directory)

@nicoddemus
Copy link
Member

Closing this for now, seems like using --basetemp is a good workaround. Feel free to chip in if we should re-open.

@The-Compiler
Copy link
Member

FWIW I have this in my testsuite for a similar issue:

@pytest.fixture()
def short_tmpdir():
    with tempfile.TemporaryDirectory() as tdir:
        yield py.path.local(tdir)

@yihuang
Copy link

yihuang commented Oct 8, 2020

FWIW I have this in my testsuite for a similar issue:

@pytest.fixture()
def short_tmpdir():
    with tempfile.TemporaryDirectory() as tdir:
        yield py.path.local(tdir)

this solution will cleanup dir automatically after test, not good for development.
seems --basetemp is good, the only thing is you can't configure it in ini, have to pass it in every run.

@koffie
Copy link

koffie commented May 23, 2021

could it at least be made easier to use this workaround and make basetmp something that is configurable in the pytest config file so that I don;t need to remember it passing it as an option every single time?

@The-Compiler
Copy link
Member

You can configure any command line option in the config via addopts.

@yihuang
Copy link

yihuang commented May 24, 2021

Another solution is just set env var TMPDIR=/tmp in current profile.

@koffie
Copy link

koffie commented May 24, 2021

@The-Compiler

Thanks, that works.

For some reason I was expecting:
to work

[tool:pytest]
basetemp = /tmp/pytest

but luckily

[tool:pytest]
addopts = --basetemp=/tmp/pytest

does exactly what I want

@RonnyPfannschmidt
Copy link
Member

@koffie please note that the basepmp option deletes the target folder

@koffie
Copy link

koffie commented May 24, 2021

@RonnyPfannschmidt thanks for the heads up. That is why I created a specific folder for pyrest tests and used --basetemp=/tmp/pytest so that my other temporary files keep existing (at least temporarily). And also why I did not do --basetemp=/tmp. Or are you implying that there is also a way of achieving the same result without deleting the target folder?

@RonnyPfannschmidt
Copy link
Member

@koffie current there isn't, but people miss the delete sometimes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants