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

Rewrite test_build_page_empty test #2613

Merged
merged 3 commits into from Oct 13, 2021

Conversation

mondeja
Copy link
Contributor

@mondeja mondeja commented Oct 11, 2021

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 11, 2021

https://stackoverflow.com/a/49718531/3451029

You can't mock the second argument of isinstance(), no. The documentation you found concerns making a mock as the first argument pass the test. If you want to produce something that is acceptable as the second argument to isinstance(), you actually have to have a type, not an instance (and mocks are always instances).
You could use a subclass instead of MyClass instead

So instead of mock.patching jinja.environment.Template, we could try to subclass it:

...
class Template(jinja.environment.Template):
    def render(*args, **kwargs):
        return ""

jinja.environment.Template = Template
...

@mondeja mondeja changed the title Uncomment build empty page test Rewrite test_build_page_empty test Oct 11, 2021
@mondeja
Copy link
Contributor Author

mondeja commented Oct 11, 2021

I think the easiest here is to just mock up the render method.

@mondeja mondeja marked this pull request as ready for review October 11, 2021 12:43
@oprypin oprypin merged commit 3ebb884 into mkdocs:master Oct 13, 2021
@mondeja mondeja deleted the build_page_empty-test branch October 13, 2021 22:23
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.

None yet

4 participants