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

Tests showing behaviour with pytest importlib mode. #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,35 @@ jobs:

- name: Run tests
run: tox -e py

import-mode-importlib:
name: import-mode=importlib
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master

- name: Set up Python
uses: actions/setup-python@v2

- name: Install tox
run: pip install tox

- name: Run tests
run: tox -e import-mode-importlib

import-mode-prepend:
name: import-mode=prepend
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master

- name: Set up Python
uses: actions/setup-python@v2

- name: Install tox
run: pip install tox

- name: Run tests
run: tox -e import-mode-prepend
17 changes: 17 additions & 0 deletions tests/test_importlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from datetime import datetime as from_datetime
import datetime as toplevel_datetime

from freezegun import freeze_time


def test_from_datetime():
# Importing the datetime class doesn't work when pytest is using import-mode=importlib.
# This is supposed to become the default, according to the documentation: https://docs.pytest.org/en/latest/changelog.html?highlight=importlib#pytest-6-0-0rc1-2020-07-08
with freeze_time("2019-01-01"):
assert from_datetime.utcnow().year == 2019


def test_top_level_datetime():
# freezegun works as expected when we're importing the datetime module
with freeze_time("2019-01-01"):
assert toplevel_datetime.datetime.utcnow().year == 2019
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
# and then run "tox" from this directory.

[tox]
envlist = py36, py37, py38, py39, pypy3, mypy
envlist = py36, py37, py38, py39, pypy3, mypy, import-mode-importlib, import-mode-prepend

[testenv]
commands = pytest --cov {posargs}
deps = -rrequirements.txt

[testenv:import-mode-importlib]
commands = pytest --import-mode=importlib tests/test_importlib.py
deps = -rrequirements.txt

[testenv:import-mode-prepend]
commands = pytest --import-mode=prepend tests/test_importlib.py
deps = -rrequirements.txt

[testenv:mypy]
deps =
mypy
Expand Down