Hi Tom,

On 9 November 2014 19:18, Tom Viner <t...@viner.tv> wrote:
> The four options I can think of to gain access to this variable:
> - monkey patch rewrite.rewrite_asserts
> - edit rewrite_asserts and paste in the logging code above:
>     -- temporarily, by each developer, on each occasion required
>     -- permanently, but only running when a certain debug flag is active
> - expose the rewritten AST via a new hook
>
> monkey patch is my preferred option, because if I can make it work, a plugin
> could be written. I just need some help to find an appropriate hook to do
> the monkey patching before pytest gets going with the AssertionRewritingHook
> and calls rewrite_asserts. Without knowledge of an early-running hook, I
> could only get this working by patching rewrite_asserts then calling
> pytest.main myself, see
> https://gist.github.com/tomviner/13c95cdb1e159028fc0b

Would this work by using monkeypatching, but using a method on
_pytest.pytester.TmpTestDir which wraps around inline_run or
inline_runsource?  That would seem like a fairly reasonable approach.
It could simply skip with an appropriate message if the meta lib is
importable and print the reversed python code to stdout for capsys to
collect.

If you would like to go the full plugin way I believe you just need to
hook in before collection happens.  I imagine pytest_configure would
be a reasonable hook for that, but have to admit I haven't tried it.


Regards,
Floris
_______________________________________________
pytest-dev mailing list
pytest-dev@python.org
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to