[pytest-dev] Questions about paramtrize and csv files

Thomas CARPENTIER carpentier.th at gmail.com
Thu Apr 18 13:46:43 CEST 2013


Ok, so my problem is just about generating datas...
Thanks for your help.

Thomas

---------------------
Thomas CARPENTIER
155 Rue Fleury
92140 CLAMART

Tel : 06.18.09.10.97
Mail : carpentier.th at gmail.com



On Thu, Apr 18, 2013 at 1:24 PM, holger krekel <holger at merlinux.eu> wrote:

> On Thu, Apr 18, 2013 at 12:51 +0200, Thomas CARPENTIER wrote:
> > Thanks but I still have the same errors :(
>
> Here is a simple test module that works:
>
>     def pytest_generate_tests(metafunc):
>         datas = [("http://something", "hello", "world", "123123")] * 44
>         metafunc.parametrize(("url", "name", "lastname", "idCustomer"),
>                              datas)
>
>
>     def test_data(url, name, lastname, idCustomer):
>         assert 0, locals()
>
> This will run 44 tests as expected.    And of course you are free to
> generate your "datas" in whichever way you like.
>
> holger
>
>
>
>
> > I will tried something else ....
> >
> > ---------------------
> > Thomas CARPENTIER
> > 155 Rue Fleury
> > 92140 CLAMART
> >
> > Tel : 06.18.09.10.97
> > Mail : carpentier.th at gmail.com
> >
> >
> >
> > On Thu, Apr 18, 2013 at 12:34 PM, holger krekel <holger at merlinux.eu>
> wrote:
> >
> > > hi Thomas,
> > >
> > > On Thu, Apr 18, 2013 at 12:19 +0200, Thomas CARPENTIER wrote:
> > > > Hi Holger,
> > > >
> > > >
> > > > here you can find my code : http://pastebin.com/fmitjbw2
> > > >
> > > > and here the csv : http://pastebin.com/UHv2XPt5
> > > >
> > > > the tracebacks : http://pastebin.com/E5p3tLCR
> > > >
> > > > thanks.
> > >
> > > If those 44 "datas" rows each contain 4-tuples you can just call
> > >
> > >     metafunc.parametrize(("url", "name", "lastname", "idCustomer"),
> datas)
> > >
> > > The extra [] list around "datas" leads to the error.
> > >
> > > holger
> > >
> > > >
> > > >
> > > >
> > > > ---------------------
> > > > Thomas CARPENTIER
> > > > 155 Rue Fleury
> > > > 92140 CLAMART
> > > >
> > > > Tel : 06.18.09.10.97
> > > > Mail : carpentier.th at gmail.com
> > > >
> > > >
> > > >
> > > > On Thu, Apr 18, 2013 at 11:35 AM, holger krekel <holger at merlinux.eu>
> > > wrote:
> > > >
> > > > > hi Thomas,
> > > > >
> > > > > On Thu, Apr 18, 2013 at 11:24 +0200, Thomas CARPENTIER wrote:
> > > > > > Hi,
> > > > > >
> > > > > > I'm working with pytest since few weeks now for automate my
> > > functionnal
> > > > > > tests using Webdriver and python. And i have some questions about
> > > how to
> > > > > > paramatrize tests.
> > > > > >
> > > > > > After reading docs, i've setup my tests like :
> > > > > >
> > > > > > @pytest.mark.parametrize(("Url", "name", "LastName",
> "IdCustomer"), [
> > > > > >  ("http://myurl.com", "myname", "mylastname", "12345"),
> > > > > > ])
> > > > > > def test_get_infos_about_client(Url, name, Lastname, IdCustomer):
> > > > > >     #Do something with arguments
> > > > > >     [...]
> > > > > >
> > > > > >
> > > > > > My problem is I've 2 testing environnements ENV1 and ENV2,
> however
> > > datas
> > > > > (
> > > > > > in particular IdCustomer  are not the same between ENV1 and ENV2
> (
> > > these
> > > > > > datas are generated during the creation of the Customer)
> > > > > >
> > > > > > So , I'm thinking about use csv files to inject datas in place of
> > > > > > parametrize function. But I did'nt find any docs about it. Is it
> > > > > possible?
> > > > > >
> > > > > > I've tried
> > > > > >
> > > > > > def pytest_generate_tests(metafunc):
> > > > > >     #read csv file
> > > > > >     metafunc.parametrize(header, datas)
> > > > > >
> > > > > > But it doesn't work!
> > > > > >
> > > > > > Can I do the same thing with another method ?
> > > > >
> > > > >
> > > > > usually pytest_generate_tests is the right place to perform
> > > > > config-dependent parametrization.  Could you post what you
> > > > > tried there concretely including failure tracebacks?
> > > > >
> > > > > holger
> > > > >
> > > > >
> > > > > > Thnaks for your help
> > > > > >
> > > > > >
> > > > > > Thomas
> > > > >
> > > > > > _______________________________________________
> > > > > > Pytest-dev mailing list
> > > > > > Pytest-dev at python.org
> > > > > > http://mail.python.org/mailman/listinfo/pytest-dev
> > > > >
> > > > >
> > >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20130418/0d47e172/attachment.html>


More information about the Pytest-dev mailing list