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 the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-appengine+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/86f581f9-886b-4cf9-8cc2-e07c76df07b5%40googlegroups.com.