pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Fixed error where filename too long being not caught #10169

Open PurityLake opened this issue 3 years ago • 7 comments

head-fork: PurityLake/pytest compare: filename-length-fix

base-fork: pytest-dev/pytest base: main

Refers to #10169

I simply added a except statement to catch the OSError

Also just noticed a fairly large typo in the commit message.

PurityLake avatar Jul 27 '22 17:07 PurityLake

This doesn't fully resolve the problem. It works if the user was trying to specify a file, but If you define a custom flag and that flag is too long pytest fails with your error instead of working. If you change to

            except OSError:
                pass # Assuming this isn't a file

that fixes my use case, but I don't know if it will cause breakage in other cases

jdckmz avatar Jul 27 '22 22:07 jdckmz

So what should be done if the arg is not a path or file as in your case?

It seems in this case it is assumed that at this point a path is assumed.

PurityLake avatar Jul 27 '22 23:07 PurityLake

Yes. I don't know why arguments are being assumed to be paths when they're not. I put more details in my comment on the bug report https://github.com/pytest-dev/pytest/issues/10169#issuecomment-1198326337

jdckmz avatar Jul 28 '22 19:07 jdckmz

Well from what I can tell you can make a fixture in conftest.py to fix your problem like so:

@pytest.fixture
def xxxxx_flags(request):
    return request.config.getoption("--xxxxx_flags")

This seems to stop pytest from assuming it's a path but I believe you would then need to run your own command line parsing for something like that.

PurityLake avatar Jul 28 '22 23:07 PurityLake

Seems the tests are failing for Windows. The code coverage fails if I don't invoke the internal method but my test still covers the UsageError (without the newer part to the test). Is it ok to not invoke the internal method or should I work to fix this?

PurityLake avatar Aug 03 '22 16:08 PurityLake

im wondering, since the original issue is about passing long options that may be unknown, should we perhaps ignore argument items that follow option syntax as separate detail

i do believe on actual too long filenames pytest should fail in any case as part of fail early

RonnyPfannschmidt avatar Aug 05 '22 10:08 RonnyPfannschmidt

@RonnyPfannschmidt I think the issue is, is that the argument needs to be declared prior to it getting to this point to not be considered a path. The part my tests cover is an actually filename but I believe I can add a quick check for a potential option but how should it be dealt with? Ignore it, or raise a UsageError?

PurityLake avatar Aug 05 '22 14:08 PurityLake

Well from what I can tell you can make a fixture in conftest.py to fix your problem like so:

@pytest.fixture
def xxxxx_flags(request):
    return request.config.getoption("--xxxxx_flags")

This seems to stop pytest from assuming it's a path but I believe you would then need to run your own command line parsing for something like that.

This does not seem to work for me since this Path.exists() is called before any of the conftest.py logic.

arichardson avatar May 11 '23 22:05 arichardson