Re: unittest for system testing

Discussion in 'Python' started by Mark Lawrence, Oct 18, 2012.

  1. On 18/10/2012 01:22, Rita wrote:
    > Hi,
    >
    > Currently, I use a shell script to test how my system behaves before I
    > deploy an application. For instance, I check if fileA, fileB, and fileC
    > exist and if they do I go and start up my application.
    >
    > This works great BUT
    >
    > I would like to use python and in particular unittest module to test my
    > system and then deploy my app. I understand unittest is for functional
    > testing but I think this too would be a case for it. Any thoughts? I am not
    > looking for code in particular but just some ideas on how to use python
    > better in situations like this.
    >


    Plenty of options here
    http://wiki.python.org/moin/PythonTestingToolsTaxonomy and an active
    mailing list that I read via gmane.comp.python.testing.general

    --
    Cheers.

    Mark Lawrence.
     
    Mark Lawrence, Oct 18, 2012
    #1
    1. Advertising

  2. Sorry for breaking threading, but the original post has not come through
    to me.

    > On 18/10/2012 01:22, Rita wrote:
    > Hi,
    >
    > Currently, I use a shell script to test how my system behaves before I
    > deploy an application. For instance, I check if fileA, fileB, and fileC
    > exist and if they do I go and start up my application.


    Do you run the shell script once, before installing the application, or
    every time the application launches?

    Do you realise that this is vulnerable to race conditions? E.g:

    Time = 10am exactly: shell script runs, fileA etc exist;

    Time = 10am and 1 millisecond: another process deletes fileA etc;

    Time = 10am and 2 milliseconds: application launches, cannot find
    fileA etc and crashes.


    Depending on what your application does, this could be a security hole.

    Regardless of what the shell script reports, to be robust your Python
    application needs to protect against the case that fileA etc are missing.
    Even if all it does is report an error, save the user's work and exit.


    > This works great BUT
    >
    > I would like to use python and in particular unittest module to test my
    > system and then deploy my app. I understand unittest is for functional
    > testing but I think this too would be a case for it. Any thoughts? I am
    > not looking for code in particular but just some ideas on how to use
    > python better in situations like this.


    Well, you *could* use unittest, but frankly I think that's a case of
    using a hammer to nail in screws. Unittest is awesome for what it does.
    It's not so well suited for this.

    Compare these two pieces of code (untested, so they probably won't work
    exactly as given):

    # sample 1
    import os
    import sys
    for name in ['fileA', 'fileB', 'fileC']:
    if not os.path.exists(name):
    print('missing essential file %s' % name)
    sys.exit(1)

    run_application()



    # sample 2
    import os
    import sys
    import unittest

    class PreRunTest(unittest.TestCase):
    list_of_files = ['fileA', 'fileB', 'fileC']
    def testFilesExist(self):
    for name in self.list_of_files:
    assertTrue(os.path.exists(name)

    total_tests, failed_tests = unittest.testmod() # I think...

    if failed_tests != 0:
    sys.exit(1)

    run_application()



    I think the first sample is much to be preferred, and not just because it
    is a couple of lines shorter. There's less magic involved.


    --
    Steven
     
    Steven D'Aprano, Oct 18, 2012
    #2
    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. Paul Moore
    Replies:
    9
    Views:
    621
    Roy Smith
    Feb 21, 2005
  2. Paul  Moore
    Replies:
    1
    Views:
    395
    Paul Moore
    Oct 14, 2008
  3. Tim Chase
    Replies:
    8
    Views:
    249
    Roy Smith
    Sep 29, 2011
  4. Dwight Hutto
    Replies:
    2
    Views:
    203
    Dwight Hutto
    Oct 18, 2012
  5. Dave Angel

    Re: unittest for system testing

    Dave Angel, Oct 18, 2012, in forum: Python
    Replies:
    0
    Views:
    189
    Dave Angel
    Oct 18, 2012
Loading...

Share This Page