2

I have a python script called script.py, this need a input A and generate a output B.

A -> script.py -> B

every time I add a new feature, I need to check that the program generate the same output.

how I can automated this tests type ?

what is the name of this tests type ?

exists some python module for this tests type ?

2
  • something like this, mv B _B; python script.py A; diff B _B Commented Feb 14, 2014 at 12:50
  • @theAlse , yes, I'm thinking in some similar ... maybe a automated diff process. But for not reinvent the wheel, I'm searching more opinions about practices and modules. Commented Feb 14, 2014 at 12:54

3 Answers 3

1

From what I understand,
You want to test if that piece of code (unit) is doing what it's supposed to. That's Unit Testing.

What you can do is make a test that gives script.py it's input (A), and gets the output produced. Then you can just check if the output matches.

class OutputTestCase(unittest.TestCase):

    def get_output(self, input):
       ...  # You haven't mentioned how "input" is taken or how output is taken.

    def test_script(self):
       input = ...
       expected = ...

       output = self.get_output(input)
       self.assertEqual(output, expected)

PS: That's how PLY tests it's code. And I'm fiddling with it!

Sign up to request clarification or add additional context in comments.

Comments

0

You can write an except script to automate this.

Comments

0

You can use pytest for your testing. So what you can do is create a testing_suite.py and put your tests in it with name starting as test_ for ex: test_B, test_C etc

# testing_suite.py
import pytest

def test_B:
          proc = subprocess.Popen(['python', 'script.py',  'arg1'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
          output = proc.communicate()[0]
          if output == 'B':
                     print "testB done" # or something else depends on you

def test_C:
          ....
          ....

then you can run as:

$> py.test

So this should execute all tests with test_. Please check pytest doc here for test discovery rules.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.