Skip to content

BytesWarning: Comparison between bytes and string #651

@AliyevH

Description

@AliyevH

Describe the bug
When using python with '-b' option it raises warning BytesWarning: Comparison between bytes and string.

How To Reproduce

from pyfakefs.fake_filesystem_unittest import Patcher
import shutil

file_name = '2.txt'

class TestCustomClass(unittest.TestCase):
    def setUp(self):
        self.patcher = Patcher()
        self.patcher.setUp()
        self.patcher.fs.create_file(file_name)

    def test_1(self):
        shutil.rmtree(file_name, ignore_errors=True)
        ... 

Your environment

Linux-5.4.0-90-generic-x86_64-with-Ubuntu-20.04-focal
Python 3.7.12 (default, Oct  1 2021, 10:07:43) [GCC 9.3.0]
pyfakefs 3.5.8

https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/fake_filesystem.py#L3204

I have fixed this issue with changing line
if target_directory in (b'.', u'.'):
to
if target_directory in (b'.'.decode('utf-8'), u'.'):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions