Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated execution of the same test #108

Open
d-maurer opened this issue Jul 7, 2020 · 2 comments
Open

Repeated execution of the same test #108

d-maurer opened this issue Jul 7, 2020 · 2 comments

Comments

@d-maurer
Copy link
Contributor

d-maurer commented Jul 7, 2020

In some cases, the same test is executed repeatedly.

I have observed this behavior with the following scenario: (test) module ma with a TestCase class A; (test) module "mb" contains from ma import A and derives TestCase class B from A. In my case, the motivation has been to run all A tests in a different set up (defined by B). When I run the test suite, all A tests are executed twice; in addition, the B tests are executed (as intented).

The explanation is quite simple: when the runner collects the TestCase classes from a given module, it does not check whether the class was actually defined by the module; it is sufficient that it contains a reference to the class -- this may be a feature. Therefore, in the scenario above, mb gives test classes A and B; A is selected a second time from ma.

When one is aware of this behavior one can fairly easily avoid repetitions: replace from ma import A ... class B(A) ... by import ma ... class B(ma.A) .... But many people won't be aware. Therefore, I suggest to check for repetitive execution of the same test is the identical context (--> layer) and avoid it.

@jamadden
Copy link
Member

jamadden commented Jul 7, 2020

The stdlib unittest runner does the same thing in Python 2 and Python 3. Given module-level fixtures (setUpModule), that definitely makes sense.

I'm not sure zope.testrunner supports those (if not I think it should, same with setUpClass), but there are probably other reasons for it.

Since I don't see a clear win, this mostly seems like a gratuitous difference from the standard library, so for right now I would be -0.5.

@d-maurer
Copy link
Contributor Author

d-maurer commented Jul 7, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants