Skip to content
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

BytesWarning: Comparison between bytes and string #651

Closed
AliyevH opened this issue Dec 6, 2021 · 2 comments
Closed

BytesWarning: Comparison between bytes and string #651

AliyevH opened this issue Dec 6, 2021 · 2 comments

Comments

@AliyevH
Copy link

AliyevH commented Dec 6, 2021

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'.'):

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Dec 6, 2021

Thanks, but your change would defy the purpose of the line, which is to check both bytes and str variants. Your change would be the same as if target_directory in ('.'):, which would break the case of target_directory == b'.'.
I'm not sure about that warning; it could probably be avoided by using an isinstance check, but that would make the code unnecessary more complicated.

Also, there are a few more such warnings in the code - I will have a look at all of them, but that has not a high priority, as the code works fine despite the warning.

@AliyevH AliyevH closed this as completed Dec 6, 2021
@AliyevH
Copy link
Author

AliyevH commented Dec 6, 2021

@mrbean-bremen Thanks

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Jan 8, 2022
- make bytes warning an error in test run
- see pytest-dev#651
mrbean-bremen added a commit that referenced this issue Jan 9, 2022
- make bytes warning an error in test run
- see #651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants