man-group / man-group/pytest-plugins

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

Open
#145 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug windows
Dominant language
Python
Stars
597
Forks
89
PR merge metrics
No merged PRs in 30d

Description

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
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
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 🤔

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with `pytest --profile` using the long parametrized byte string shown in the issue. Start at `pytest_profiling.py` line 80, where `prof.dump_stats(prof_filename)` is called, and verify that profiling completes on Windows without an invalid or overlong output filename.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.