Running single test from unittest.TestCase via command line

Alois Mahdal :

In our team, we define most test cases like this:

One "framework" class ourtcfw.py:

import unittest

class OurTcFw(unittest.TestCase):
    def setUp:
        # something

    # other stuff that we want to use everywhere

and a lot of test cases like testMyCase.py:

import localweather

class MyCase(OurTcFw):

    def testItIsSunny(self):
        self.assertTrue(localweather.sunny)

    def testItIsHot(self):
        self.assertTrue(localweather.temperature > 20)

if __name__ == "__main__":
    unittest.main()

When I'm writing new test code and want to run it often, and save time, what I do is that I put "__" in front of all other tests. But it's cumbersome, distracts me from the code I'm writing and the commit noise this creates is plain annoying.

So e.g. when making changes to testItIsHot(), I want to be able to do this:

$ python testMyCase.py testItIsHot

and have unittest run only testItIsHot()

How can I achieve that?

I tried to rewrite the if __name__ == "__main__": part, but since I'm new to Python, I'm feeling lost and keep bashing into everything else than the methods.

phihag :

This works as you suggest - you just have to specify the class name as well:

python testMyCase.py MyCase.testItIsHot

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Running single test from unittest.TestCase via command line - with ddt

Karma: Running a single test file from command line

Is it possible to run a single test method from a python unittest.TestCase with a reference to the method?

how to run a tf.test.TestCase from jupyter notebook - UnrecognizedFlagError: Unknown command line flag 'f'

Phantom tests after switching from unittest.TestCase to tf.test.TestCase

Ignoring single PHPCS rule when running from command line

Running php via command line

What are the columns in the output of running a jmeter test from the command line?

How to write Rspec test for running file from command line?

Run single test from a JUnit class using command-line

Need help in running a command involving multiple single and double quotes on windows command line via bsub

Django test runner not respecting unittest.TestCase?

How to get fixture value from test method declared within a unittest TestCase class?

Running PackageMaker from command line

Running this from command line in Java

Running Scheme from the command line

Running Python from Command Line

running pug from command line

Clojure.test and Leinigen: How to run just a single test from command line

Running jupyter via command line on Windows

Running LaTeX via command line on Ubuntu server

Skip single test with maven with command line options

Is there command line command to test appsrc and appsink in a single line for gstreamer pipeline?

Java UnitTest multiple command Line input from System.in

Running .dtsx file via command line programmatically from a winform c#

Stop abstract django.test TestCase class from running test also

Why doesn't running test-with-groovy from ant command line in a netbeans project run the tests?

Jmeter - How do I see sampler data following running a test from Command line?

Running individual XCTest (UI, Unit) test cases for iOS apps from the command line