[TIP] py.test for distributed blackbox testing using Selenium

holger krekel holger at merlinux.eu
Wed Jan 25 06:25:34 PST 2012


Hi Baiju,

On Sun, Jan 22, 2012 at 18:55 +0530, Baiju M wrote:
> On Sun, Jan 22, 2012 at 2:29 AM, holger krekel <holger at merlinux.eu> wrote:
> > Hi Baiju,
> >
> > On Sat, Jan 21, 2012 at 22:11 +0530, Baiju M wrote:
> >> I was trying to use the xdist plugin for distributed black box testing
> >> using Selenium.
> >> I have N number of isolated identical app servers (same DB, same
> >> configuration etc.).
> >> I was following this instruction:
> >> http://pytest.org/latest/xdist.html#running-tests-in-a-python-subprocess
> >>
> >> Each test should connect to the above mentioned distinct app servers. What
> >> approach would be good in this kind of situation to get the IP& PORT of these
> >> servers ?  Should I go for some external queue ?  Or can I do it using a
> >> a queue in the same process ?  May some serialization of this app server
> >> detailes (IP&PORT) would be sufficient ?
> >> I am looking to forward to your opinions/suggestions.
> >
> > You can extend pytest to send the different nodes different information
> > and they can then make sure to provide it to tests or for setup
> > purposes.  For an exmaple, look at this acceptance test:
> >
> >    https://bitbucket.org/hpk42/pytest-xdist/src/1d2909839e98/testing/acceptance_test.py#cl-159
> >
> > to see how information is exchanged between the master and slave nodes.
> > If you setup some information/list of port/IPs on the master you
> > should be able to use those to send them to the slaves and then
> > use them from a pytest_sessionstart() or similar hooks.  Almost
> > all hooks have access to the test "config" object which has the
> > "slaveinput" attribute on slaves.
> 
> I tried to use "pytest_configure_node' with some "funcarg".
> But I couldn't provide distinct values to slaves:
> 
> I was using "browser" (Selenium WebDriver object) funcarg for existing
> test cases.
> So, I tried to combine these things.
> 
> Here is my code:
> https://gist.github.com/1657059
> 
> I am always getting the same browser.
>
> May be I am missing something.

With your code each slaves sees its own copy of all_nodes and used_nodes.
The subprocesses do not share data structures.  What you need to do
is make pytest_configure_node (which runs on the master) send different values to each node.  For a quick demonstration something like:

    # conftest.py
    def pytest_configure(config):
        config._counter = 0

    def pytest_configure_node(node):
        node.slaveinput['data'] = node.config._counter
        node.config._counter += 1

    def pytest_funcarg__mydata(request):
        return request.config.slaveinput['data']

    # test_some.py
    def test_hello(mydata):
        print mydata
        assert 0

    def test_world(mydata):
        print mydata
        assert 0

should give you something like what you need.  
HTH,
holger



More information about the testing-in-python mailing list