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

Add setUpClassPyfakefs convenience method #758

Merged
merged 1 commit into from
Dec 8, 2022

Conversation

mrbean-bremen
Copy link
Member

@mrbean-bremen mrbean-bremen commented Dec 7, 2022

Tasks

  • Unit tests added that reproduce the issue or prove feature is working
  • Fix or feature added
  • Entry to release notes added
  • Pre-commit CI shows no errors
  • Unit tests passing
  • For documentation changes: The Read the Docs preview builds and looks as expected

- only available from Python 3.8 onwards
- also add class-scoped 'fs_class' fixture
- handle patcher for doc tests separately
Copy link

@buhtz buhtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just gave comments about improving the example code in the docstring.



class ExampleTestCase(TestCase):
def setUpClass(cls):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be an @classmethod as decorator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks like I botched the example... thanks, will correct this!


class ExampleTestCase(TestCase):
def setUpClass(cls):
self.setUpClassPyfakefs()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO not self. but cls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True of course.

class ExampleTestCase(TestCase):
def setUpClass(cls):
self.setUpClassPyfakefs()
cls.file_path = "/test/file.txt"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so complicated? ;)
Just do

pathlib.Path('/test/file.txt').touch()

Isn't one of the great things of your package that I can do all file operations as usual because your package does the patching in background for me. No need to use fake_fs() or create_file(). Or do I misunderstand something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you understand correctly, this is just to demonstrate that you can access the fake fs from there, say to setup things that cannot be done in the real fs (like setting the file system size). But I may change this to make this more clear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have waited for a review before merging this - I tend to overlook simple stuff like that myself, especially in the evenings after my day job... next time.

@buhtz
Copy link

buhtz commented Dec 9, 2022

The GitHub review mechanic do not show the correct lines here in my comments. But I hope you can understand them also.

@mrbean-bremen mrbean-bremen deleted the class_setup branch March 14, 2023 18:42
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

Successfully merging this pull request may close these issues.

2 participants