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

pytest-profiling: File name can become too long on Windows #145

Open
danielschenk opened this issue Aug 20, 2019 · 1 comment · May be fixed by #215
Open

pytest-profiling: File name can become too long on Windows #145

danielschenk opened this issue Aug 20, 2019 · 1 comment · May be fixed by #215

Comments

@danielschenk
Copy link

danielschenk commented Aug 20, 2019

I have a parametrized test of which one of the invocations uses a (fairly long) byte string as input.
Because pytest tries to print parametrized tests in the most useful way, this byte string ends up in the full test name, which pytest-profiling then uses for the file with the profiling results. This causes an issue on Windows which (unfortunately) has a fairly short file name length limit:

pytest --profile
============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-5.1.0, py-1.8.0, pluggy-0.12.0
rootdir: C:\Software\tryout\pytest_tryouts
plugins: cov-2.7.1, ordering-0.6, profiling-1.7.0, pycharm-0.6.0
collected 1 item

test_foo.py .                                                            [100%]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\_pytest\main.py", line 191, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\_pytest\main.py", line 235, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\_pytest\main.py", line 256, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pluggy\callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\site-packages\pytest_profiling.py", line 80, in pytest_runtest_protocol
INTERNALERROR>     prof.dump_stats(prof_filename)
INTERNALERROR>   File "c:\users\rnd10\appdata\local\programs\python\python37-32\lib\cProfile.py", line 46, in dump_stats
INTERNALERROR>     with open(file, 'wb') as f:
INTERNALERROR> OSError: [Errno 22] Invalid argument: 'C:\\Software\\tryout\\pytest_tryouts\\prof\\test_foo[_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff_xff].prof'

============================== 1 passed in 0.02s ==============================

Is this something pytest-profiling could handle in some way? It would be a pity if I could not write tests like this one and profile them 🤔

@eeaston
Copy link
Collaborator

eeaston commented Nov 19, 2021

Thanks for raising - yes the plugin should truncate the name on Windows. Sorry for the ridiculously long time to reply!

dalemyers added a commit to dalemyers/pytest-plugins that referenced this issue Apr 22, 2023
Windows seems to return `EINVAL` instead of `ENAMETOOLONG`.

Fixes man-group#145
@dalemyers dalemyers linked a pull request Apr 22, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants