Multiple python files in the same folder with Nose

40 Views Asked by At

I gave some test that I want to run with Nose, but in the same folder I have multiple files with tests, there is a way to ignore all the files? Another one than ignore files? I have multiple files and it is time consuming to write all in the ignore list. My tests are receiving parameters from the user.

Thanks

# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import os
import unittest
import argparse
import textwrap
import nose

class BaseSilTest(unittest.TestCase):
    """Sil base test
    Base functionality is:
        - Integrity of mts joint cfg
        - No crash/exception during empty recording
    """

    def __init__(self, methodName='runTest', _testcase=None):
        super(BaseSilTest, self).__init__(methodName)

        self.x = _testcase[0]
        self.y = _testcase[1]


    def test_00(self):

        verdict = True
        if self.x > 100:
            verdict = False

        self.assertEqual(verdict, True, "Test failed")

    def test_01(self):

        verdict = True
        if self.y > 100:
            verdict = False

        self.assertEqual(verdict, True, "Test failed")

    @staticmethod
    def parametrize(testcase):
        testloader = unittest.TestLoader()
        testnames = testloader.getTestCaseNames(BaseSilTest)
        suite = unittest.TestSuite()
        for name in testnames:
            suite.addTest(BaseSilTest(name, _testcase=testcase))
        return suite


def parse_arguments():
    """Parse the command line arguments"""
    parser = argparse.ArgumentParser(
        description="Test Script",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=textwrap.dedent("""Test Script """))
    parser.add_argument("-testcase", "--testcase",
                        nargs="*",
                        help="Test parameters",
                        type=int)
    return parser.parse_args()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    ARGS = parse_arguments()

    TEST_SUITE = unittest.TestSuite()
    TEST_SUITE.addTest(BaseSilTest.parametrize(ARGS.testcase))
    TEST_RESULT = nose.run(TEST_SUITE, argv=['nosetests', '-v', '--processes=-1', '--ignore-files=try_test.py])

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
0

There are 0 best solutions below