質問

I'm using Pyramid framework for my application. I'm writing unit tests (tests.py file), where I want to:

  1. get the actual request instead of dummyRequest and

  2. also want to get the values of variables defined in config (development.ini) file.

I have gone through How to get an actual Pyramid request when unit testing question as well, but didn't get much from it.

Let me know how above can be achieved.

役に立ちましたか?

解決

For your first "want", you can see this well-written SO post: How to get an actual Pyramid request when unit testing

It suggests to utilize the DummyRequest. "The thing to realize whenever you are unit testing (which is different from functional tests) is that you are testing a small 'unit'. This unit does not require a 'real' request, nor does it require a fully working system."


For your second "want", you can refer to the (1) Pyramid docs and (2) an SO post:

  1. http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html#adding-a-custom-setting
  2. how can i get the ini data in pyramid?

Essentially, in your view function, you can use request.registry.settings or pyramid.threadlocal.get_current_registry().settings, it behaves like a dictionary.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top