Comments (11)
Yep, sorry I forgot to reply earlier; I saw a shiny object that day.
It is good to close.
from behave-django.
Answer 1: Yes, behave-django is using LiveServerTestCase
. There are no changes remaining in tables after a test scenario is completed, because of the inner workings of TransactionTestCase
.
Answer 2: I can only imagine adding reset_sequences = True
to our BehaviorDrivenTestCase (maybe in BehaviorDrivenTestRunner) by default. Should be doable to even make this configurable.
from behave-django.
FWIW, I have a workaround, which also (I think) validates my assessment above.
from behave_django.testcase import BehaviorDrivenTestCase
from django.test import TransactionTestCase
old_test_case_init = BehaviorDrivenTestCase.__init__
def new_test_case_init(self, *k, **kw):
old_test_case_init(self, *k, **kw)
TransactionTestCase.reset_sequences = True
BehaviorDrivenTestCase.__init__ = new_test_case_init
from behave-django.
Re: Answer 2... I can look into making it configurable
from behave-django.
Adding this (configurable) feature is certainly a sweet addition to behave-django. Apart from that I guess you're probably doing something in your tests that is discouraged to do. The documentation says:
Unless you are explicitly testing primary keys sequence numbers, it is recommended that you do not hard code primary key values in tests.
In other words: You should not test on primary key values. -- There must be a better way.
Also, a reason to not include reset_sequences = True
by default in our TestCase:
Using
reset_sequences = True
will slow down the test, since the primary key reset is an relatively expensive database operation.
from behave-django.
@JCapriotti is this still an issue you feel worth to be fixed? Can you contribute the necessary changes and place a pull request?
from behave-django.
I'm closing this due to lack of activity / interest. Please feel free to reopen this again any time.
from behave-django.
Shiny object? Not sure what you're referring to. Want to elaborate?
from behave-django.
(I just arrived here from Google, but I think @JCapriotti is saying he got distracted by a shiny obj---oh, look a squirrel!)
from behave-django.
@JCapriotti 's workaround also proves helpful if you need to set serialized_rollback = True
for your test cases.
I was having a problem where data migrations that are part of the main site set-up were being wiped after the first scenario. There's a good description of that problem here:
https://stackoverflow.com/questions/26273921/django-1-7-testing-losing-data-from-data-migration
The serialized_rollback
workaround to that problem is suggested here:
https://code.djangoproject.com/ticket/23640
But I couldn't figure out how to add it to the test case until reading this thread. So if anyone else ends up here looking for the same, I found that adding this to the environment.py
file worked:
from behave_django.testcase import BehaviorDrivenTestCase
from django.test import TransactionTestCase
old_test_case_init = BehaviorDrivenTestCase.__init__
def new_test_case_init(self, *k, **kw):
old_test_case_init(self, *k, **kw)
TransactionTestCase.serialized_rollback = True
BehaviorDrivenTestCase.__init__ = new_test_case_init
from behave-django.
As mentioned by a friendly user in our Gitter chat room a solution approach may be to set serialized_rollback = True
on the testcase.
See also
- https://kevinwiliarty.com/posts/behave-django-monkey-patches/
- https://docs.djangoproject.com/en/stable/topics/testing/overview/#rollback-emulation
from behave-django.
Related Issues (20)
- Replace deprecated multi_db (after 2020) HOT 1
- Suggest page object module for headless testing HOT 1
- Documentation of django_ready hook incorrectly lists "scenario" as a second positional argument HOT 2
- Fixtures silently do nothing when --simple is specified, and no documentation calls this out HOT 10
- Getting more programmatic flexibility on the testcase type used in scenarios HOT 4
- Cleanup of custom permissions between scenarios HOT 1
- multiple features and before_all initial setup HOT 2
- how to assess test case code coverage? HOT 5
- Testing ASGI Django HOT 5
- Custom Runner e TestCase HOT 19
- Add support for customized LiveServerTestCase with selenium-hub support HOT 1
- Support latest stable version of Python and Django
- Use GitHub Actions CI HOT 1
- Looking for (co-)maintainer! 🔥🙏🦠🔥🐍 HOT 3
- Tables are not created for test_database while running behave test HOT 3
- Investigate potential bug in `environment.get_url()`
- Inconsistent when using behave --simple HOT 1
- Objects not only being created in test database
- Behave v1.2.7.dev3 breaks management command HOT 5
- NEEDS: .readthedocs.yaml config-file soon (before 2023-09) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from behave-django.