<div dir="ltr">One extra note:<div><br></div><div><div>`py.test -s` is required to see rewritten AST output, even for failing tests, because the output comes while</div><div>tests are being collected and rewritten, not during the execution of a test. So pytest's "show output upon</div><div>fail" cannot help here.</div></div><div><br></div><div>If anyone knows how to tie the output to particular tests, that would be great.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 1 March 2015 at 23:01, Tom Viner <span dir="ltr"><<a href="mailto:tom@viner.tv" target="_blank">tom@viner.tv</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for your ideas Floris, I've managed to get it working with your pytest_configure suggestion.<div><br></div><div>The only extra bit was having to disable reading the cached pyc files that pytest writes, as these skip my monkeypatch.<div><br></div><div>Take a look, it's simple to use:</div><div><a href="https://gist.github.com/tomviner/c3537c2f2b2b8172f83e" target="_blank">https://gist.github.com/tomviner/c3537c2f2b2b8172f83e</a></div><div><br></div><div>If there's any demand, I could easily make this a pip installable pytest plugin.</div><div><div class="h5"><div><div class="gmail_extra"><br><div class="gmail_quote">On 13 November 2014 at 23:34, Floris Bruynooghe <span dir="ltr"><<a href="mailto:flub@devork.be" target="_blank">flub@devork.be</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Tom,<br>
<span><br>
On 9 November 2014 19:18, Tom Viner <<a href="mailto:tom@viner.tv" target="_blank">tom@viner.tv</a>> wrote:<br>
> The four options I can think of to gain access to this variable:<br>
> - monkey patch rewrite.rewrite_asserts<br>
> - edit rewrite_asserts and paste in the logging code above:<br>
>     -- temporarily, by each developer, on each occasion required<br>
>     -- permanently, but only running when a certain debug flag is active<br>
> - expose the rewritten AST via a new hook<br>
><br>
> monkey patch is my preferred option, because if I can make it work, a plugin<br>
> could be written. I just need some help to find an appropriate hook to do<br>
> the monkey patching before pytest gets going with the AssertionRewritingHook<br>
> and calls rewrite_asserts. Without knowledge of an early-running hook, I<br>
> could only get this working by patching rewrite_asserts then calling<br>
> pytest.main myself, see<br>
> <a href="https://gist.github.com/tomviner/13c95cdb1e159028fc0b" target="_blank">https://gist.github.com/tomviner/13c95cdb1e159028fc0b</a><br>
<br>
</span>Would this work by using monkeypatching, but using a method on<br>
_pytest.pytester.TmpTestDir which wraps around inline_run or<br>
inline_runsource?  That would seem like a fairly reasonable approach.<br>
It could simply skip with an appropriate message if the meta lib is<br>
importable and print the reversed python code to stdout for capsys to<br>
collect.<br>
<br>
If you would like to go the full plugin way I believe you just need to<br>
hook in before collection happens.  I imagine pytest_configure would<br>
be a reasonable hook for that, but have to admit I haven't tried it.<br>
<br>
<br>
Regards,<br>
Floris<br>
</blockquote></div><br></div></div></div></div></div></div>
</blockquote></div><br></div>