Jc2k / pytest-markdown

Run tests in your markdown
11 stars 2 forks source link

Support assertion rewriting and source code display #1

Closed theY4Kman closed 6 years ago

theY4Kman commented 6 years ago

This changes how the modules get created, so pytest can show source code and intermediate assertion values during error reporting:

_________________________________ test_the_namerator _________________________________

full_name = 'John Jacob last'

    def test_the_namerator(full_name):
>       assert full_name == 'John Jacob Jingleheimer-Schmidt'
E       AssertionError: assert 'John Jacob last' == 'John Jacob Jingleheimer-Schmidt'
E         - John Jacob last
E         + John Jacob Jingleheimer-Schmidt

quickstart:13: AssertionError
============================== 1 failed in 0.04 seconds ==============================

Previously:

_________________________________ test_the_namerator _________________________________

full_name = 'John Jacob last'

>   ???
E   AssertionError

<string>:13: AssertionError
============================== 1 failed in 0.07 seconds ==============================
theY4Kman commented 6 years ago

This plugin is goddamn awesome, btw. Thank you so much :D

Jc2k commented 6 years ago

Thank you very much for this - the lack of source in test fails had been bugging the hell out of me! Glad you like it 👍

theY4Kman commented 6 years ago

Word up! I'd ended up quite plastered last night and vomited a couple dozen paragraphs onto a work PR, babbling on about "incorrectness of end-user docs increases exponentially for every step away from their implementation" and "if ya can put your docs right beside your tests, they're more likely to be read and written". This morning I went to check if the name was available for a pytest plugin I wanted to release, and saw this at the top of the list. Serendipity :)

I love your idea of "tests beside docs" as opposed to my "docs beside tests" — 'cause ultimately they should serve the same purpose, but docs are meant to be visible.

Plus, my README contains all my tests now :P https://github.com/theY4Kman/pytest-lambda