Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does freezetime work with pytest.fixture? #190

Closed
elcolie opened this issue Jun 14, 2017 · 2 comments
Closed

Does freezetime work with pytest.fixture? #190

elcolie opened this issue Jun 14, 2017 · 2 comments

Comments

@elcolie
Copy link

elcolie commented Jun 14, 2017

My goal is
create the object with specific timezone in order to suppress the warning message when run testcases
I try follow shreevatsar commented on Aug 18, 2015. I know he uses Python2
#87

Software Versions:

python3.6.0
django==1.10.6
djangorestframework-jwt==1.9.0
djangorestframework==3.6.1
pyjwt==1.4.2              # via djangorestframework-jwt
pytest-django==3.1.2
pytest==3.1.2             # via pytest-django
@pytest.fixture
def orders(staff):
    from datetime import datetime
    from pytz import timezone
    d = datetime(2015, 8, 18, 8, 51, 50, tzinfo=timezone('America/Los_Angeles'))
    with freeze_time(d):
        mommy.make(Order, _quantity=1, car_info={"color": "Black"}, customer={"name": "Lord Elcolie"},
                   staff=Staff.objects.first(), shop=Shop.objects.first())

PyTest test case

def test_get_order(car_data, admin_user, orders):
    from rest_framework.test import force_authenticate

    factory = APIRequestFactory()
    user = User.objects.get(username='admin')
    view = OrderViewSet.as_view({'get': 'list'})

    request = factory.get('/api/orders/')
    force_authenticate(request, user=user)
    response = view(request)
    assert 200 == response.status_code
    assert 1 == len(response.data.get('results'))

PyTest result
It timezone does not solve warning

apps/orders/tests.py::test_get_order
  /Users/el/.pyenv/versions/3.6.0/envs/eneos-pos-web/lib/python3.6/site-packages/django/db/models/fields/__init__.py:1372: RuntimeWarning: DateTimeField Order.created_at received a naive datetime (2017-06-14 00:00:00) while time zone support is active.
    RuntimeWarning)
@spulec
Copy link
Owner

spulec commented Jun 15, 2017

See here: #176

@spulec spulec closed this as completed Jun 15, 2017
@elcolie
Copy link
Author

elcolie commented Jun 15, 2017

I will try my best to understand it. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants