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 reamde for .pytest_cache #3608

Merged
merged 8 commits into from
Jun 22, 2018
Merged

add reamde for .pytest_cache #3608

merged 8 commits into from
Jun 22, 2018

Conversation

avirlrma
Copy link
Contributor

@avirlrma avirlrma commented Jun 21, 2018

fixes #3519

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
@avirlrma avirlrma closed this Jun 21, 2018
@avirlrma avirlrma reopened this Jun 21, 2018
ran black
removed unused imports and variables
@avirlrma
Copy link
Contributor Author

@nicoddemus I have added the tests,the readme content and everything else as well.
Please review the tests

@avirlrma avirlrma requested a review from nicoddemus June 21, 2018 09:51
@coveralls
Copy link

coveralls commented Jun 21, 2018

Coverage Status

Coverage increased (+0.06%) to 92.717% when pulling 0d3914b on avirlrma:features into 9d60cf2 on pytest-dev:features.

Copy link
Member

@nicoddemus nicoddemus left a 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. 👍

self._ensure_readme()

def _ensure_readme(self):
content_readme = """# pytest cache directory #
Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

@nicoddemus nicoddemus Jun 21, 2018

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. 😁

pytest_plugins = ("pytester",)


class Helper(object):
Copy link
Member

@nicoddemus nicoddemus Jun 21, 2018

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.

return readme.isfile()


class TestReadme(Helper):
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do.

class TestReadme(Helper):

def test_readme_passed(self, testdir):
testdir.tmpdir.join("test_a.py").write(
Copy link
Member

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
""")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it

@nicoddemus
Copy link
Member

solves #3519

A small detail, solves is not one of the keywords recognized by GH to automatically close issues when PRs get merged, see https://help.github.com/articles/closing-issues-using-keywords.

Copy link
Member

@nicoddemus nicoddemus left a 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!

@nicoddemus nicoddemus merged commit de98939 into pytest-dev:features Jun 22, 2018
@avirlrma
Copy link
Contributor Author

Thanks, @nicoddemus for helping me out all the time and bearing with me.

@nicoddemus
Copy link
Member

Not at all, your contribution is very much appreciated! 👍

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.

3 participants