Hi all

We have a bunch of functional tests derived from
StaticLiveServerTestCase using selenium that have started failing
after upgrading from Django 1.8 to Django 1.11.

The database is initially populated via data migrations, but after
running one test it all the data loaded via migrations has been
removed from the database, and all subsequent tests fail because the
expected data is not in the database.

Note that this is after running one test, not one test case; if we run
each test from an affected test case individually, they pass; if we
run the entire test case, the first test passes and the rest fail.

These tests were initially written under Django 1.8, with the data
coming from the same migrations, and they worked correctly in Django
1.8.

I looked back through the release notes and documentation; rollback
emulation[1] via serialized_rollback=True appeared promising, but
after enabling it we had IntegrityErrors immediately after finishing
the first test; it appears as though when it was attempting to re-load
the serialized data back in to the database, the data was still there:

Any thoughts? I've included some of the output below - running without
serialized_rollback[2] and with[3]. Unfortunately, I cannot share much
of the code itself.

Cheers

Tom

[1] 
https://docs.djangoproject.com/en/1.11/topics/testing/overview/#rollback-emulation
[2]
tests.functional_tests.test_search_defaults.DefaultSearchResultsTest
    test_browsing_to_a_saved_search_keeps_the_default_hero_block ...
[<Group: dev_group>, <Group: vip_dev_group>, <Group: CMS Editors>]
ok
    test_infinite_scrolling_of_search_results ... []
ERROR
screenshotting to
/home/london/te/moat-effortless_web_app/reports/screendumps/DefaultSearchResultsTest.test_infinite_scrolling_of_search_results-window0-2
018-02-23T11.59.55.png
dumping page HTML to
/home/london/te/moat-effortless_web_app/reports/screendumps/DefaultSearchResultsTest.test_infinite_scrolling_of_search_results-window
0-2018-02-23T11.59.55.html
writing har log to
/home/london/te/moat-effortless_web_app/reports/screendumps/DefaultSearchResultsTest.test_infinite_scrolling_of_search_results-window0-
2018-02-23T11.59.55.har.logwriting browser log to
/home/london/te/moat-effortless_web_app/reports/screendumps/DefaultSearchResultsTest.test_infinite_scrol
ling_of_search_results-window0-2018-02-23T11.59.55.browser.logLast URL
visited was http://dev-vip04.london.mintel.ad:53066/facelift/
http requests made during test:



======================================================================
ERROR: test_infinite_scrolling_of_search_results
(tests.functional_tests.test_search_defaults.DefaultSearchResultsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File 
"/data/home/london/te/moat-effortless_web_app/web_app/tests/functional_tests/test_search_defaults.py",
line 10, in test_infinite_scrolling_of_searc
h_results
    homepage = HomePage.browse_to_directly(self)
  File 
"/data/home/london/te/moat-effortless_web_app/web_app/tests/functional_tests/pages/base.py",
line 61, in browse_to_directly
    page.wait_for_page_load()
  File 
"/data/home/london/te/moat-effortless_web_app/web_app/tests/functional_tests/pages/home.py",
line 248, in wait_for_page_load
    self.test.waitFor(_assert_page_ready)
  File 
"/data/home/london/te/moat-effortless_web_app/web_app/tests/functional_tests/base.py",
line 394, in waitFor
    return function_with_assertion(*args)
  File 
"/data/home/london/te/moat-effortless_web_app/web_app/tests/functional_tests/pages/home.py",
line 246, in _assert_page_ready
    'div.home-page'
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 397, in find_element_by_css_selector
    return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 707, in find_element
    {'using': by, 'value': value})['value']
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 196, in execute
    self.error_handler.check_response(response)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py",
line 181, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: {"errorMessage":"Unable to find
element with css selector
'div.home-page'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"104","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:38766","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using\":
\"css selector\", \"sessionId\":
\"073fdaf0-1891-11e8-aa90-778d14a3b7d7\", \"value\":
\"div.home-page\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/073fdaf0-1891-11e8-aa90-778d14a3b7d7/element"}}
Screenshot: available via screen

----------------------------------------------------------------------
Ran 2 tests in 28.708s

FAILED (errors=1)


[3]
tests.functional_tests.test_search_defaults.DefaultSearchResultsTest
    test_browsing_to_a_saved_search_keeps_the_default_hero_block ...
[<Group: dev_group>, <Group: vip_dev_group>, <Group: CMS Editors>]
ok
ERROR

======================================================================
ERROR: test_infinite_scrolling_of_search_results
(tests.functional_tests.test_search_defaults.DefaultSearchResultsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/test/testcases.py",
line 209, in __call__
    self._pre_setup()
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/test/testcases.py",
line 856, in _pre_setup
    self._fixture_setup()
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/test/testcases.py",
line 903, in _fixture_setup
    connections[db_name]._test_serialized_contents
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/backends/base/creation.py",
line 131, in deserialize_db_fro
m_string
    obj.save()
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/core/serializers/base.py",
line 205, in save
    models.Model.save_base(self.object, using=using, raw=True, **kwargs)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/models/base.py",
line 838, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update,
using, update_fields)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/models/base.py",
line 924, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/models/base.py",
line 963, in _do_insert
    using=using, raw=raw)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/models/manager.py",
line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/models/query.py",
line 1076, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
line 1112, in execute_sql
    cursor.execute(sql, params)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/backends/utils.py",
line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/raven/contrib/django/client.py",
line 123, in execute
    return real_execute(self, sql, params)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/backends/utils.py",
line 64, in execute
    return self.cursor.execute(sql, params)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/utils.py",
line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/backends/utils.py",
line 64, in execute
    return self.cursor.execute(sql, params)
  File 
"/data/home/london/te/moat-effortless_web_app/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py",
line 328, in execute
    return Database.Cursor.execute(self, query, params)
IntegrityError: column group_id is not unique

----------------------------------------------------------------------
Ran 1 test in 9.415s

FAILED (errors=1)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1JwNA4F2X2MNxZLgvj69yCzT%3DNs8wNo-NyiAEeovkR%2BkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to