Skip to content

Commit

Permalink
Make block_device fixture return str instead of pathlib.Path
Browse files Browse the repository at this point in the history
This is done because `pathlib.Path` automatically adds a trailing
backslash to Windows paths of the shape `\\.\PhysicalDriveN`.
Trying to open such a path including the trailing backslash raises
`PermissionError`. This issue is tracked at python/cpython#78079.
  • Loading branch information
thunze committed Mar 21, 2023
1 parent a14b7bf commit 2309cdd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def block_device(request, tempdir):
encoding='utf-8',
)
device_path = completed_process.stdout.rstrip()
yield Path(device_path)
yield device_path

# Clean up
subprocess.run(
Expand All @@ -84,7 +84,7 @@ def block_device(request, tempfile):
encoding='utf-8',
)
device_path = completed_process.stdout.rstrip()
yield Path(device_path)
yield device_path

# Clean up
subprocess.run(['losetup', '-d', device_path])
Expand All @@ -107,5 +107,5 @@ def block_device(request, tempfile):
logical or physical sector size for a virtual block device. In that case,
values which cannot be used are ignored.
Returns a ``pathlib.Path`` object representing the path of the block device.
Returns a string representing the path of the block device.
"""
4 changes: 2 additions & 2 deletions tests/test_platform_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_device_properties(block_device, size_expected, sector_size_expected) ->
"""Test that ``device_size()`` and ``device_sector_size()`` return the expected
values.
"""
with block_device.open('rb') as f:
with open(block_device, 'rb') as f:
size_actual = platform_specific.device_size(f)
sector_size_actual = platform_specific.device_sector_size(f)

Expand Down Expand Up @@ -86,5 +86,5 @@ def test_reread_partition_table(block_device):
"""Test that correctly invoking ``reread_partition_table()`` does not raise an
exception.
"""
with block_device.open('rb') as f:
with open(block_device, 'rb') as f:
platform_specific.reread_partition_table(f)

0 comments on commit 2309cdd

Please sign in to comment.