Testing advise

18 views
Skip to first unread message

Lele Gaifax

unread,
Dec 6, 2020, 7:49:28 AM12/6/20
to pylons-...@googlegroups.com
Hi all,

I'm used to have something like the following in my tests setup:

https://gitlab.com/metapensiero/SoL/-/blob/master/tests/server/conftest.py#L45

that allows me to use the route name in my tests instead of the view URL,
like:

https://gitlab.com/metapensiero/SoL/-/blob/master/tests/server/test_data.py#L15

I wonder if I'm missing some existing similar facility, of if instead that
approach could be suggested in the documentation, say here

https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/testing.html#creating-functional-tests

What do you think?

Thanks&bye, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
le...@metapensiero.it | -- Fortunato Depero, 1929.

Michael Merickel

unread,
Dec 6, 2020, 4:47:57 PM12/6/20
to pylons-...@googlegroups.com
The "recommended" approach for doing this would be to create a DummyRequest and then use its route_url, etc methods. This will allow you to use Pyramid's actual url generation apis instead of re-implementing them yourself, as well as avoiding needing to use the private route mapper.

req = DummyRequest()
req.route_url(...)

It's natural to use the DummyRequest as well because Pyramid's url generation facilities are always relative to the properties of a WSGI request like scheme, host, script_name, etc.

That being said your fixtures look great.

- Michael
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/87h7ozqkqx.fsf%40metapensiero.it.

Steve Piercy

unread,
Dec 6, 2020, 5:34:17 PM12/6/20
to pylons-...@googlegroups.com
Hi Lele,

Your project would be a nice addition to Powered by Pyramid:

https://trypyramid.com/community-powered-by-pyramid.html

Please consider submitting a pull request to add it. Thank you!

--steve

Lele Gaifax

unread,
Dec 8, 2020, 5:27:00 AM12/8/20
to pylons-...@googlegroups.com
Steve Piercy <steve.pi...@gmail.com>
writes:

> Your project would be a nice addition to Powered by Pyramid

Oh, thank you! I issued PR#293: unfortunately I was not able to verify the
change on my local machine this morning, but will do as time permits, if
there's something wrong with it.

ciao, lele.

Lele Gaifax

unread,
Dec 8, 2020, 5:30:08 AM12/8/20
to pylons-...@googlegroups.com
Michael Merickel <mmer...@gmail.com> writes:

> The "recommended" approach for doing this would be to create a DummyRequest

Thank you Michael, I will surely explore that way.

ciao, lele.
Reply all
Reply to author
Forward
0 new messages