fralau / mkdocs-macros-plugin

Create richer and more beautiful pages in MkDocs, by using variables and calls to macros in the markdown code.
https://mkdocs-macros-plugin.readthedocs.io
Other
337 stars 51 forks source link

Create a unit testing framework #241

Closed fralau closed 1 month ago

fralau commented 1 month ago

It would be useful to have a unit testing framework, in particular for non-regression-testing.

With PR #239, @timvink proposes a pattern already used on mkdocstrings.

For a detailed discussion see #237 about hooks, particularly:

You can test the functions / custom classes separately of course. I actually do prefer small 'integration' testing using mkdocs build.

What's worked for me is to build up a collection of small standalone examples (like here https://github.com/timvink/mkdocs-table-reader-plugin/tree/master/tests/fixtures) and test whether they fail (sometimes they should) or succeed, and whether the resulting html page(s) contain expected output. See f.e. https://github.com/timvink/mkdocs-table-reader-plugin/blob/master/tests/test_build.py

Originally posted by @timvink in https://github.com/fralau/mkdocs-macros-plugin/issues/237#issuecomment-2333405315

fralau commented 1 month ago

General description

The testing rig proposed is based on a number of components:

timvink commented 1 month ago

I think you could replace CliRunner with a basic subprocess.call command also, if you want to keep your dev dependencies light

fralau commented 1 month ago

I have played around enough with subprocess.call() to appreciate the simplicity of CliRunner 🙂.

fralau commented 1 month ago

@timvink I am studying the solution you adopted, as well as pytest.

I would have question: what is the advantage of creating a separate test directory for each build, compared to using the regualr site subdirectory (which is in .git_ignore)?

timvink commented 1 month ago

Instead of pytest --pdb to drop into the debugger, I can use mkdocs serve -f path_to_yaml together with a breakpoint() anyehere in the code to drop into the debugger there.

fralau commented 1 month ago

The follow-up will be done on #244. Closing this, with the label "keep in mind".