pytest
pytest copied to clipboard
Fixed error where filename too long being not caught #10169
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.
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
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.
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
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.
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?
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 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?
Well from what I can tell you can make a fixture in
conftest.pyto 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.