unittest -- simple question

Discussion in 'Python' started by Brian, Nov 2, 2003.

  1. Brian

    Brian Guest

    Hello;

    I am writing my test modules that are separate from the modules they
    test. The test modules can be invoked with if __name__ == "__main__" when
    run from a command line. Right now, if __name__ == "__main__", the test
    module executes runTests(), which defines a suite of tests. From the
    module being tested, I am calling into the test module -- to the function
    runTests(), if __name__ == "__main__".

    Is this how people make the tests executable from the module be tested?

    Many thanks,

    Brian.
    Brian, Nov 2, 2003
    #1
    1. Advertising

  2. Brian

    Ian Bicking Guest

    On Nov 1, 2003, at 10:30 PM, Brian wrote:
    > I am writing my test modules that are separate from the modules they
    > test. The test modules can be invoked with if __name__ == "__main__"
    > when
    > run from a command line. Right now, if __name__ == "__main__", the test
    > module executes runTests(), which defines a suite of tests. From the
    > module being tested, I am calling into the test module -- to the
    > function
    > runTests(), if __name__ == "__main__".
    >
    > Is this how people make the tests executable from the module be tested?


    If I understand what you're saying, you have something like:

    def runTests():
    ....

    if __name__ == '__main__':
    runTests()

    ? If so, then yes, this is the conventional and approved way to make
    any module into a simple program, tests included.

    --
    Ian Bicking | | http://blog.ianbicking.org
    Ian Bicking, Nov 2, 2003
    #2
    1. Advertising

  3. Brian

    John J. Lee Guest

    Brian <> writes:
    [...]
    > Is this how people make the tests executable from the module be tested?


    Yes, but people often use the convenience function unittest.main


    John
    John J. Lee, Nov 2, 2003
    #3
  4. Brian

    Jp Calderone Guest

    On Sat, Nov 01, 2003 at 11:30:20PM -0500, Brian wrote:
    > Hello;
    >
    > I am writing my test modules that are separate from the modules they
    > test. The test modules can be invoked with if __name__ == "__main__" when
    > run from a command line. Right now, if __name__ == "__main__", the test
    > module executes runTests(), which defines a suite of tests. From the
    > module being tested, I am calling into the test module -- to the function
    > runTests(), if __name__ == "__main__".
    >
    > Is this how people make the tests executable from the module be tested?
    >


    I typically decorate my modules with the following preable:


    # -*- test-case-name: package.test.test_modulename -*-

    and then hit F9 when I want the tests to run.

    Jp
    Jp Calderone, Nov 2, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Wesley

    unittest problems

    Richard Wesley, Jul 28, 2003, in forum: Python
    Replies:
    3
    Views:
    279
    John J. Lee
    Jul 30, 2003
  2. Will Stuyvesant

    How do you do unittest?

    Will Stuyvesant, Aug 1, 2003, in forum: Python
    Replies:
    5
    Views:
    363
    Will Stuyvesant
    Aug 2, 2003
  3. Paul Moore
    Replies:
    12
    Views:
    519
    Garth T Kidd
    Oct 23, 2003
  4. Ian Bicking
    Replies:
    3
    Views:
    263
    John J. Lee
    Oct 22, 2003
  5. Paul  Moore
    Replies:
    1
    Views:
    384
    Paul Moore
    Oct 14, 2008
Loading...

Share This Page