3

My questions are:

  1. How can I set dependencies between testing classes, functions or even full testing modules, so that some don't get executed if others failed?

  2. How do I pass (propagate) the results of a test to the subsequent?

I know that similar questions has been asked here, but I still think I'm missing something here.

Let's say I have a class implementing an algorithm that requires training and evaluation steps. Thus, let's consider 3 tests:

  • "test_allocation"
  • "test_train"
  • "test_eval".

These are sequential and hence, it'll be useless (impossible) to run one if the previous has failed. (If it helps, I'm thinking on pattern recognition algorithms)

Here they suggested to alter the internal state of the object so that "test_eval" can be executed even if "test_train" has failed. I understand and agree with this. However, there're cases where this is not really possible/practical, e.g. if the training process implements a really complex algorithm (am I supposed to take my calculator out and do all the maths by hard!? No, thank you).

The most reasonable answer I have found to my question is this, which is implemented on pytest.

Solved!

Only halve of it :-(

This only works within a testing class, which works well for my example above. But how do I achieve the same dependency between two different testing classes? Or even between testing modules?. Why would I want this? Imagine a big module encompassing several sub-modules and design in a pyramid way. If the base sub-module fails, it doesn't have sense to test the rest of the sub-modules.

I also need to have access to the result of "test_train" from within "test_eval". Otherwise I'll have to train the algorithm again, which in many case is computationally expensive. How do I pass the results of "test_train" to "test_eval"? Setting the object as a class property doesn't seem to work (testing methods can't modify properties "?" Or they can but changes don't materialize outside the function. OR I'm doing something wrong here). Then... the only solution I can think of is to allocate the object externally (global variable), but this doesn't seem elegant to me.

What am I missing here?

Thanks in advance

Community
  • 1
  • 1
Marcos
  • 450
  • 4
  • 12
  • A similar question to 1. was asked [here](https://stackoverflow.com/questions/27318493/fail-remaining-pytest-tests-if-a-specific-one-fails) by @Joiya550 a couple of months ago, but it's still unsanswered. Moreover, it was set as a duplicate of [this](http://stackoverflow.com/questions/12411431/pytest-how-to-skip-the-rest-of-tests-in-the-class-if-one-has-failed), which it might be true strictly speaking, **BUT** (as the link in my question) the accepted answer only solves the problem for *classes*, and it's not generably applicable (at least I can't see how) for functions or modules. – Marcos Mar 06 '15 at 13:25

0 Answers0