0
votes

I want to set up a unittest style test class, which uses a pytest fixture in the setUp method. Something like this:

def myTestClass(unittest.TestCase):
    def setUp():
        self.URL = fixture_url

    def test_a():
        # points tests at self.URL

It would have a conftest.py file which adds a command line option for the URL. (I have already built this, but I'm not sure how to set up the fixture.)

I want to have multiple test classes testing different features. Then I will run py.test giving a URL which all of the classes will use in their setUp.

If there is some other better way to achieve this I'd be happy to hear it!

1

1 Answers

0
votes

As there's no responses I'll post my makeshift solution:

I created a new file: config.py, which used environment variables to construct the parameters. i.e.

# contents of config.py
THIS_URL = os.getenv('TEMP_URL', 'https://www.thisisatest.com')

# contents of test_*.py
...
def setUp(self):
    self.URL = config.THIS_URL

This works fine. The environmental variables can be set temporarily from the command line in the normal way.