_add_c_drive() failure when user does not have access to c:
See original GitHub issueDescribe the bug
When using pyfakefs 4.3.0 with pytest, the patcher’s setUp function calls _add_c_drive. This works when I execute locally or on my build server when executed manually. It fails, however, when run by the build server using a service account. I think the problem is that the service account does not have access to read the C: drive. Side note: for these tests I actually want to simulate a Linux filesystem. The setUp function is setting up C: before I can intercept the fs object and set the os to Linux.
Final parts of the stack trace:
...\lib\site-packages\pyfakefs\fake_filesystem_unittest.py:727: in setUp
self.fs._add_c_drive()
...\lib\site-packages\pyfakefs\fake_filesystem.py:1026: in _add_c_drive
self.root.get_entry('C:') .st_dev = self.last_dev
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pyfakefs.fake_filesystem.FakeDirectory object at 0x0000023C9DD61610>
pathname_name = 'C:'
def get_entry(self, pathname_name):
"""Retrieves the specified child file or directory entry.
Args:
pathname_name: The basename of the child object to retrieve.
Returns:
The fake file or directory object.
Raises:
KeyError: if no child exists by the specified name.
"""
pathname_name = self._normalized_entryname(pathname_name)
> return self.contents[to_string(pathname_name)]
E KeyError: 'C:'
How To Reproduce
-
Install pytest (6.1.2) and pyfakefs (4.3.0)
-
Create a simple test like the following:
import pytest def describe_will_this_fail(): @pytest.fixture def fixture(fs): fs.os = "linux" def it_should_not_fail(fs, fixture): assert 1 == 1 -
Run
pytestfrom an account that does not have access toC:.
Your enviroment
Windows-10-10.0.17763-SP0
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]
pyfakefs 4.3.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
I have Lost access to C:\ Drive. How can I regain the
Right click Start button to open Run box, copy and paste in netplwiz, press Enter. Highlight your account, then click Properties, then Group ......
Read more >Access C Drive files in UWP AppService - Stack Overflow
Example: I want to access "C:\Test\sample.txt" file from UWP AppServices. I have tried the below code. but throwing error(Additional information: Access is ......
Read more >C Drive Access is Denied in Windows 10 - Fixed
When you are denied to access C drive, you cannot access, change, save, or delete files and folders. Why C drive access is...
Read more >Please help me to get access to c: Drive because I messed up ...
Access is denied. I can't open Regedit anymore because I get this error: Network Error: Windows cannot access C:\WINDOWS\regedit.exe ...
Read more >MDTechVideos - YouTube
C :\ Is Not Accessible. Access Is Denied Error In Windows 10/8.1/8 [Tutorial]On a computer the following problems appeared after Windows ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks - that was a kind of micro-optimization that probably was too fragile. I think I’ll just revert that (Windows-specific) optimization, I didn’t like it anyway. It will add a millisecond to the test setup under Windows, but I can check later if this can be optimized in a nicer way.
The bugfix release is out now.