Yes, but we’re still on the Python 2 environment, hence the migration. Once
we're on Cloud NDB we need to finish eliminating testbed and move off
taskqueues, though I think our usage of the latter is small enough that I
can do it at the since time we move to Python 3.

Ryan, thanks for the additional suggestions. I ran into an error when
trying to set the context in the unittest setUp() method that said there
was already a context open, and I wasn't immediately able to figure out why
the context wasn't getting closed in tearDown(). I was able to get things
unstuck a bit by overwriting the unittest.TestCase run() method as below,
though that seems like an ugly approach. But you gave me some new things to
try out, so thank you!

def run(self, result=None):
with ndb_client.context():
super(BackstabbrTestCase, self).run(result)

On Wed, Feb 19, 2020 at 8:34 AM 'noverlyjoseph' via Google App Engine <
[email protected]> wrote:

> Google do recommend to use local environment for testing instead of
> dev_appserver, and to use pytest for unit testing.[1]
> dev_appserver was recommend for First Generation App Engine
>
>
> [1]
> https://cloud.google.com/appengine/docs/standard/python3/testing-and-deploying-your-app#running_locally
>
>
> On Tuesday, February 18, 2020 at 2:30:32 PM UTC-5, Ryan B wrote:
>>
>> hi jon!
>>
>> On Tuesday, February 18, 2020 at 5:42:26 AM UTC-8, Jon Grover wrote:
>>>
>>> On Thursday, January 16, 2020 at 1:47:03 PM UTC-8, Ryan B wrote:
>>> 1) First and foremost, I had repeated issues with dev_appserver
>>> connecting to my production datastore despite having set all the correct
>>> environment variables and setting the --support_datastore_emulator flag. I
>>> was finally able to solve it by explicitly passing *--env_var
>>> DATASTORE_EMULATOR_HOST=localhost:8081*, but I'm not immediately sure
>>> how to do that from within our unittest framework and I'm very worried
>>> about our unit tests writing to the production datastore. (For the time
>>> being, I used the gcloud CLI to change my project to a dummy one.)
>>>
>>
>> yes! this one was/is disappointing. it's a hole in dev_appserver that
>> most likely will never be closed, since dev_appserver itself is basically
>> deprecated. i literally monkey patch the host/port into the ndb context
>> manually:
>> https://github.com/snarfed/webutil/blob/master/appengine_config.py#L39 .
>> background: https://github.com/googleapis/python-ndb/issues/238
>>
>>
>>
>>> 2) This is maybe my own unfamiliarity with NDB context, but I'm not sure
>>> what the correct way is to use the same NDB context across all unit tests.
>>> I borrowed your WSGI middleware trick for the app itself, but I haven't yet
>>> quite figured out how to apply a single context across our entire unittest
>>> suite. I tried creating a new NDB context in our base setUp method, which
>>> looked like it was working but dragged the test speed to a crawl.
>>>
>>
>> right! i do exactly that, and also reset the datastore and call
>> __enter__(), and then __exit__() in tearDown:
>> https://github.com/snarfed/bridgy/blob/master/tests/testutil.py#L282-L289
>>
>> unit tests are definitely slower now with the emulator vs testbed in the
>> python 2 runtime. one test suite of mine that does datastore operations in
>> almost every test, often many per test, takes ~50s to run 526 tests. not
>> great, but i usually iterate by running individual tests, so it doesn't
>> hurt too much.
>>
>>
>>
>>
>>> Just curious if you had any additional insights or example code
>>> available. I've already learned quite a bit by reading through your other
>>> postings, so thanks regardless.
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Google App Engine" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/google-appengine/hN_8VlRl5Dk/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-appengine/630ff6f3-1f0a-426e-b885-17fa283bb376%40googlegroups.com
> <https://groups.google.com/d/msgid/google-appengine/630ff6f3-1f0a-426e-b885-17fa283bb376%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CAMaXnizYcjOt7cN2AjJzfr8s1Up4zmQHrFKybM2R55NPUiFXhQ%40mail.gmail.com.

Reply via email to