Comments (5)
Hi @petrsynek, thank you for your feedback!
Can you take a look at #65 and let me know whether this is related or is able to give you some hints?
You're probably aware that behave-django is "just" a convenient integration of behave with Django. According to your description I'd guess the "fault" is really here in this repository, not in the actual behave tool.
Is only 3.2+ affected?
If this problem does not occur with any previous version of Django then maybe this is a real Django issue, and we'll be able to find hints in their issue tracker. I know too little about the problem to do proper research, though. Frankly, I don't know enough of ASGI in general. There is a related topic, Adding ASGI support to runserver, in the Django forum though, which might be worth investigating.
Override the integration
You can set the test client directly in environment.py
, please take a look at our documentation to see how this is done. Maybe that helps. Otherwise you might want to try to more explicitly set up your Django integration, as described in the Behave docs.
Let us know how you resolve the situation!
from behave-django.
Hi,
First, thanks for the quick reply, @bittner. I am looking into the sources right now. I will let you know the results moment I will know more.
from behave-django.
The problem was a little bit more complex than we originally thought.
1st - as we use Django to send on event webhooks, we also run client-side as part of the behave (from aiohttp web). The issue was caused by not waiting for the server to close properly.
2nd - when we started to wait for the server to close, we started to encounter this error instead
[Errno 98] Address already in use
this completely broke the run in the pipeline. The reason was that LiveServerThread from django.test.testcases got stuck for a few ms (usually on system closing of the socket, which may be slightly slower in GitLab pipeline and on VM in general); to resolve this, we modified environment.py in the following way.
from django.test.testcases import LiveServerThread
class UnsafeLiveServerThread(LiveServerThread):
"""
This class is used to monkey patch the server_thread_class attribute so that server used in
integration tests can reuse socket connection. Before we used this, we often encountered
[Errno 98] Address already in use. We assume this was because the server under test was
torn down at the end of one scenario, and when we tried to spin it up at the start of the next
scenario, the address was unavailable. To be honest, we're not sure what kind of side effects
this might have. But we're quite sure that this solved the problem with Errno 98.
"""
def _create_server(self):
return ThreadedWSGIServer(
(self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=True
)
def before_all(context):
"""
Ugly Monkey patching!
Do not try this at home!
Hack Django live Server Test case to bring back the ability to listen not only on localhost and
to start when the previous instance still lingers due to the socket closing.
"""
LiveServerTestCase.host = "0.0.0.0"
LiveServerTestCase.port = 8001
LiveServerTestCase.server_thread_class = UnsafeLiveServerThread
@classproperty
def live_server_url(cls):
return "http://%s:%s" % ("127.0.0.1", cls.server_thread.port)
LiveServerTestCase.live_server_url = live_server_url
from behave-django.
Hmmm, nice! That looks like the typical use case for behave-django. We're monkey patching like crazy, we only need an AsgiLiveServer
class (or something) to plug in when needed, when configured.
Would you want to try to turn yours into an elegant solution (e.g. use a command line switch or configuration setting) in behave-django?
from behave-django.
I don't feel qualified enough to turn this into a reasonably elegant solution :)
This is actually a pretty ugly solution as it allows you to start a new server while the old one is still running. So the right solution would be to wait for LiveServerThread to terminate.
Regarding ASGI, I think the solution must be on the side of Django anyway so that Django would be supporting ASGI more 'natively.'
from behave-django.
Related Issues (20)
- 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
- 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
- Coverage advice breaks m2m queries. HOT 2
- Dependency on Behave blocks release on PyPI
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.