Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:17:22+00:00 2026-06-17T05:17:22+00:00

Sorry for the basic question. I have used unittest method to check my models

  • 0

Sorry for the basic question. I have used unittest method to check my models in one script. Now, my question is how do I call this script from another file and save testing results. Below is my code sample:

**model_test.py**

import unittest
import model_eq #script has models

class modelOutputTest(unittest.TestCase):
    def setUp(self):
        #####Pre-defined inputs########
        self.dsed_in=[1,2]

        #####Pre-defined outputs########
        self.msed_out=[6,24]

        #####TestCase run variables########
        self.tot_iter=len(self.a_in)

    def testMsed(self):
        for i in range(self.tot_iter):
            fun = model_eq.msed(self.dsed_in[i],self.a_in[i],self.pb_in[i])
            value = self.msed_out[i]
            testFailureMessage = "Test of function name: %s iteration: %i expected: %i != calculated: %i" % ("msed",i,value,fun)
self.assertEqual(round(fun,3),round(self.msed_out[i],3),testFailureMessage)

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

The next step I want is to create another script called test_page.py, which runs the unit test script and save results to a variable (I need to post results to a webpage).

test_page.py    

from model_test.py import *
a=modelOutputTest.testMsed()

However, I got the following errors.

Traceback (most recent call last):
  File "D:\Dropbox\AppPest\rice\Rice_unittest.py", line 16, in <module>
    a= RiceOutputTest.testMsed()
TypeError: unbound method testMsed() must be called with RiceOutputTest instance as first argument (got nothing instead)

Can anyone give me some suggestions? Thanks!

Thanks for the help from Nix! My next question is: I need to test the function with two given cases in a loop. It is posted here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:17:23+00:00Added an answer on June 17, 2026 at 5:17 am

    You need to use a test runner

    test runner
    A test runner is a component which orchestrates the execution of tests and provides the outcome to the user. The runner may use a graphical interface, a textual interface, or return a special value to indicate the results of executing the tests.

    from unittest.case import TestCase
    import unittest
    from StringIO import StringIO
    class MyTestCase(TestCase):
        def testTrue(self):
            '''
            Always true
            '''
            assert True
    
        def testFail(self):
            '''
            Always fails
            '''
            assert False
    
    from pprint import pprint
    stream = StringIO()
    runner = unittest.TextTestRunner(stream=stream)
    result = runner.run(unittest.makeSuite(MyTestCase))
    print 'Tests run ', result.testsRun
    print 'Errors ', result.errors
    pprint(result.failures)
    stream.seek(0)
    print 'Test output\n', stream.read()
    

    >>> Output:  
    >>> Tests run  2
    >>> Errors  []
    >>> [(<__main__.MyTestCase testMethod=testFail>,
    >>> 'Traceback (most recent call last):\n  File "leanwx/test.py", line 15, in testFail\n                assert False\nAssertionError\n')]
    >>> Test output
    >>> F.
    >>> ======================================================================
    >>> FAIL: testFail (__main__.MyTestCase)
    >>> ----------------------------------------------------------------------
    >>> Traceback (most recent call last):
    >>>   File "leanwx/test.py", line 15, in testFail
    >>>     assert False
    >>> AssertionError
    >>>
    >>>----------------------------------------------------------------------
    >>>Ran 2 tests in 0.001s
    >>>
    >>>FAILED (failures=1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry if this is a basic question! up till now i have been creating
sorry i know this is a basic question, but i have been trying for
Sorry for this rather basic question, but I have to get some sort of
this is a really basic question, sorry! So i have this text file in
Sorry for asking a totally basic question, but if I have a synthesized property
Sorry about the wording for my question title. I have a basic HTML anchor
Sorry this is a basic question, but all my research just barely missed answering
Sorry if this is a really basic question but it's been really getting to
Sorry, another super basic ASP.NET question. this so embarrassing. I am reading the article
Sorry, this might be a basic/stupid/noob question - I am just trying to tweak

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.