nose-devs / nose

nose is nicer testing for python
http://readthedocs.org/docs/nose/en/latest/
1.36k stars 395 forks source link

Test duplicates when inheriting tests #840

Open khusseini opened 10 years ago

khusseini commented 10 years ago

Hi there, I am using nose in conjunction with needle (https://github.com/mozzymoz/needle/tree/develop). In my project I let a script generate my test files from which I inherit to make some customization.

folder structure:
- TestCheckoutbasicsFirefox.py
- generated/
    - CheckoutbasicsFirefoxBase.py

When I run TestCheckoutbasics, all tests inside are executed twice. How can I circumvent this?

from generated.CheckoutbasicsFirefoxBase import CheckoutbasicsFirefoxBase

class TestCheckoutbasicsFirefox(CheckoutbasicsFirefoxBase):
    pass
# encoding: utf-8
import needle
import time
from needle.cases import NeedleTestCase

class CheckoutbasicsFirefoxBase(NeedleTestCase):
        engine_class = 'needle.engines.perceptualdiff_engine.Engine'
        base_url = 'http://localhost/mop/relaunch/'

        @classmethod
        def get_web_driver(cls):
                return needle.driver.NeedleFirefox()

    def prepare(self):
        self.driver.execute_script("""
        $("img.lazy").trigger("unveil");
        """);
        time.sleep(1)
        pass

        def test_PurelistCheckoutnavigationView4CheckoutaddressH040(self):
                self.set_viewport_size(width=320, height=240)
                self.driver.get(self.base_url + 'checkout.address_H040.htm')
                self.prepare()
                self.assertScreenshot("#checkout-navigation", "CheckoutbasicsFirefox.purelistcheckout-navigation.view4.checkoutaddressH040")

        def test_PurelistHeaderView4CheckoutaddressH040(self):
                self.set_viewport_size(width=320, height=240)
                self.driver.get(self.base_url + 'checkout.address_H040.htm')
                self.prepare()
                self.assertScreenshot("#header", "CheckoutbasicsFirefox.purelistheader.view4.checkoutaddressH040")

        def test_PurelistFooterView4CheckoutaddressH040(self):
                self.set_viewport_size(width=320, height=240)
                self.driver.get(self.base_url + 'checkout.address_H040.htm')
                self.prepare()
                self.assertScreenshot("#footer", "CheckoutbasicsFirefox.purelistfooter.view4.checkoutaddressH040")

        def test_PurelistCheckoutnavigationView1CheckoutaddressH040(self):
                self.set_viewport_size(width=1024, height=768)
                self.driver.get(self.base_url + 'checkout.address_H040.htm')
                self.prepare()
                self.assertScreenshot("#checkout-navigation", "CheckoutbasicsFirefox.purelistcheckout-navigation.view1.checkoutaddressH040")
jszakmeister commented 10 years ago

Off-the-cuff, I'm not sure you can. Automatic test discovery and base classes within your tests present an interesting dilemma. As both can be picked up and the run as test cases, especially when they ultimately derive from unittest.TestCase.