1

I am preparing python script which will control other python and linux scripts in correct sequence. And I have one doubt about below code:

import os
import unittest

class TestDict(unittest.TestCase):

    x = factory.FileGenerator()
    os.system('./linux_script.sh')

    def test_dict(self):
        self.assertDictEqual(self.test, self.json, 'Message')

As you can see at first I am preparing files and then run linux_script.sh. Next step is to compare two dict, but it cannot be done until linux script will be completed - the script is running other application which creates .json file. Until .json file is not prepared, test_dict cannot be executed because it will fail.

Question: python will be waiting for this line to be completed: os.system('./linux_script.sh, and then run test? If not how I can force python to do that?

2
  • docs.python.org/3/library/subprocess.html#subprocess.run Commented May 20, 2018 at 13:44
  • 1
    Using a relative path for a script is inviting trouble in the future. Better to put the script in a well-known directory and add that to your PATH environment variable. Commented May 20, 2018 at 13:49

1 Answer 1

2

os.system() does wait for the command to complete before returning.

Note that, since you're calling the function directly inside the class body, this will execute when your test class is being loaded, not when it gets instantiated. If that's not what you want, move the call into the constructor, a set up method or directly into the test method itself.

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

1 Comment

I will add it to a setUp method. Thanks

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.