Hi Shujie,

On Wed, May 22, 2013 at 13:29 -0400, Liao, Shujie wrote:
> Hi,
> 
> We want to update the test result automatically from pytest to a web 
> application, we run pytest from Jenkins currently , and our plan is to run a 
> script as post step to make this happen.
> 
> We have thousands of test cases in an excel file, and now they were all 
> imported to the web tool(the tool generated a unique id for each test), the 
> problem is, the test name in web tool and from pytest are not exactly the 
> same, and so far we don't have plan as well as hands to make them the same....
> 
> Our thoughts is to pass the test id to each pytest test case, so that from 
> output result, the id becomes part of test name, then we have the map from 
> pytest test cases to the web tool.
> 
> We are looking for a feature from pytest, which can help achieve following 
> requirements:
> 
> 1.       Can easily inject an external id to each test case, both 
> non-parameterized and parameterized test.
> 
> 2.       The injected id will be part of test name in output
> 
> 3.       Without impacting existing parameterized mechanism (or need minor 
> modification is fine)
> 
> For parameterized test, I tried to use 
> @pytest.mark.parametrize(('name'),create_data,ids=['DEMO-1','DEMO-2']), of 
> them, "DEMO-1" and "DEMO-2" are ids from the test cases in web tool, I got 
> this as output:
> 
> 
> platform linux2 -- Python 2.7.3 -- pytest-2.3.4
> collected 2 items
> <Module 'test_demo.py'>
>   <Class 'TestDemo'>
>     <Instance '()'>
>       <Function 'test_generatekeypair[DEMO-1]'>
>       <Function 'test_generatekeypair[DEMO-2]'>
> 
> However, for non-parameterized test, seems this solution is less decent, 
> although we can pass the parameter without using it, still seems ugly...
> 
> 
> 
> Is there a better way we can do this?

It all depends a bit but you might look into marking your tests like this::

    # content of test_file.py

    import pytest

    @pytest.mark.id("demo1")
    def test_hello():
        pass

    @pytest.mark.id("demo2")
    def test_world():
        pass


and then implementing a hook which transfers the marks as part of the test id:

    # content of conftest.py
    
    def pytest_collection_modifyitems(items):
        for item in items:
            id = item.keywords.get("id", None)
            if id is not None and getattr(id, "args", None):
                item.name += "[%s]" % id.args[0]

which when run gives this:

    $ py.test -v test_file.py

    test_file.py:4: test_hello[demo1] PASSED
    test_file.py:8: test_world[demo2] PASSED

Of course, you could also have a different way to configure
the names in the conftest hook, e.g. by reading a file which
maps test ids to names or so.

HTH,
holger

        

> 
> 
> The information contained in this electronic mail transmission 
> may be privileged and confidential, and therefore, protected 
> from disclosure. If you have received this communication in 
> error, please notify us immediately by replying to this 
> message and deleting it from your computer without copying 
> or disclosing it.
> 
> 

> _______________________________________________
> Pytest-dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/pytest-dev

_______________________________________________
Pytest-dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to