-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 reamde for .pytest_cache #3608
Conversation
method - `ensure_readme()`
Helper class to check if readme exists in .pytest_cache directory Tests to check for readme when tests pass and when they fail
ran black removed unused imports and variables
@nicoddemus I have added the tests,the readme content and everything else as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @avirlrma,
Besides the small changes requested, we also need a CHANGELOG entry. 👍
src/_pytest/cacheprovider.py
Outdated
self._ensure_readme() | ||
|
||
def _ensure_readme(self): | ||
content_readme = """# pytest cache directory # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use textwrap.dedent
so you don't need to have the lines spill over the right side:
def _ensure_readme(self):
content_readme = textwrap.dedent("""\
# pytest cache directory #
This directory contains data from the pytest's cache plugin, \
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
**Do not** commit this to version control.
See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
""")
if self._cachedir.check(dir=True):
readme_path = self._cachedir.join("README.md")
if not readme_path.check(file=True):
readme_path.write(content_readme)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew this was wrong,but even after searching couldn't come up with a solution. Also shouldn't flake point this out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also shouldn't flake point this out?
I don't think so, the code is not wrong, but using dedent makes it more pleasing to the eyes. 😁
testing/test_cacheREADME.py
Outdated
pytest_plugins = ("pytester",) | ||
|
||
|
||
class Helper(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this class at all, it only adds to (albeit small) increase in code complexity without any benefit.
I suggest to just move the check_readme
function to TestReadme
and delete this class.
testing/test_cacheREADME.py
Outdated
return readme.isfile() | ||
|
||
|
||
class TestReadme(Helper): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this class to test_cache.py
, I don't think we need to keep this in a separate file just because of a single test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.
testing/test_cacheREADME.py
Outdated
class TestReadme(Helper): | ||
|
||
def test_readme_passed(self, testdir): | ||
testdir.tmpdir.join("test_a.py").write( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier to use testdir.makepyfile
:
testdir.makepyfile("""
def test_always_passes():
assert 1
""")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
A small detail, |
moved cache readme tests to test_cacheprovider.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great contribution, thanks @avirlrma!
Thanks, @nicoddemus for helping me out all the time and bearing with me. |
Not at all, your contribution is very much appreciated! 👍 |
fixes #3519