[TIP] REG: Reload testcases from the interpreter.

Bruno Oliveira nicoddemus at gmail.com
Thu May 4 06:02:54 PDT 2017

Hi Arun,

On Wed, May 3, 2017 at 3:34 PM arun kali raja <arunsep886 at gmail.com> wrote:

> i am trying to implement a functionality in pytest through which user can
> re-run his testcase once the testcase is completed with some modifcations
> in his testcases.
> I am trying to do this since i have a many fixtures running before the
> Testcases and  i dont want to go through the pain of executing all the
> fixtures when i want to run a failed test case sort.

IIUC you want to re-use the fixture results in different test sessions,
right? IOW:

$ pytest
# some tests fail, update some code
$ pytest
# run the failed tests, but reusing the fixture data from the 1st run

The only way to accomplish that AFAIK is to save the fixture data into disk
somewhere, and change your fixture code to re-use that data if available
instead of re-creating it from scratch.

You can use pytest's builtin cache for that:

Cache: working with cross-testrun state:

I was thinking of using the "pytest_runtest_protocol" hook and since the
> item object has a runtest method i thought making some changes in my test
> file will reflect when i do a runtest again..
> But that doesnt seem so. item has a attribute (not a member variable...
> just a scopeAttr) called module which points to the already compiled code
> and i am not able to override with my new compiled code.
> I tried to delete my test package from sys.modules but that too doesnt
> help.

I don't see how deleting things from `sys.modules` would help if you are in
a different process than the first test run.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20170504/bafa8798/attachment.html>

More information about the testing-in-python mailing list