-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
ntpath.py: ValueError: path is on mount 'C:', start on mount 'D:' error shows after calling get_full_context() from a different drive on Windows 10 #55
Comments
This seems like a defect against relpath, not against check. |
@okken : Can we consider, it is not expected that os.path return an absolute path when calling relpath and the current behvior is not really a bug, but that the function caller should handle the exception? May I work on a fix for this where the exception is caught and fallback in abspath, like: try:
filename = os.path.relpath(filename)
except ValueError as error:
filename = os.path.abspath(filename) it would produce the long path ONLY when the relative path is not possible to be built (like on wind**s system with multiple drives) |
…lback if the relpath did not work (baase on the exception produced on window with several drives)
Hi @okken , actually, I did already produce a first fix proposition, so that you can directly accept/reject my offer. By rejection, please give me a reason, so that I can offer a more appropriate solution. I hope it will be an acceptable compromise for you by using the relative path as default (I understood that you did not like the first fix because you do not like the absolute path structure, what is understandable), but providing a cleaner fallback solution based on absolute path when the relative path does not work. It will avoid testers on windows to get "unreadable" feedback with exception cascading (I am Linux fan, but unfortunatly my clients do not...). |
I'll take a look as soon-ish, life permitting. |
Alternative fix proposition for #55 : the abspath is used as fallback…
Summary:
The
check_methods.get_full_context(level)
function does not work correctly on Windows 10, error in determining filename on line 195:filename = os.path.relpath(filename)
Detailed description:
If the function was called from a file on the D drive and filename is on the C drive, then os.path.relpath will give an error:
ValueError: path is on mount 'C:', start on mount 'D:'
Pytest will failed on the ValueError exception from module ntpath.py line 703.
This behavior is possible if we override the call of any pytest_check function not from the test file, but from the module file, which is located on a different disk than the test.
What I mean is function overrides can be getted through Handlers and inheritance.
I have prepared a vivid example with overriding the behavior of the logging function.
When calling logging.info(), pytest_check.is_none() will also be called to check the assertion which will always fail.
We will also intercept all pytest logging during pytest_runtest_call()
This is where we can initialize pytest_check.is_none() from one drive while the test is on another a drive.
Perhaps there are inaccuracies in terminology in my description, I think it will be clear from the code below what I mean.
For example:
We have Python 3.9.1 with modules (logging, pytest, pytest_check) installed on disc C:/Python391/
We have tests with conftest installed on disc D:/test/ with this code:
D:/test/conftest.py:
D:/test/test_logging_assert.py:
Run the command line from the test folder on the D drive:
D:\test> C:/Python391/python.exe -m pytest --log-cli-level=info test_logging_assert.py
Actual result:
Expected Result:
Possible solution:
Change finding os.path.relpath to finding os.path.abspath:
filename = os.path.abspath(filename)
Environment:
OS: Windows 10
Python: 3.9.1
Pytest: 6.2.2
Pytest check: 1.0.1
Pull request #54
The text was updated successfully, but these errors were encountered: