7th Week of 2022
New: Add tutorial on how to use asyncio.
New: Version overriding now supports constrains.
Before you had to pin specific versions, which is not maintainable, now you can use constrains
[tool.pdm.overrides] asgiref = ">=3.2.10"
pdm update --dry-run --unconstrained
Correction: Correct the type hints of the factory.
class PersonFactory(ModelFactory[Any]): ...
Probably you've introduced an ending
/to the endpoint, so instead of asking for
/my/endpointyou tried to do
Correction: Update the tmpdir_factory type hints.
You should now use
Most of the tests work with frozen time, so it's better to freeze it by default and unfreeze it on the ones that actually need time to move.
To do that set in your
tests/conftest.pya globally used fixture:
if TYPE_CHECKING: from freezegun.api import FrozenDateTimeFactory @pytest.fixture(autouse=True) def frozen_time() -> Generator['FrozenDateTimeFactory', None, None]: """Freeze all tests time""" with freezegun.freeze_time() as freeze: yield freeze
New: Ignore a warning of a specific package.
filterwarnings = [ "error", # Until https://github.com/ktosiek/pytest-freezegun/issues/35 is merged "ignore::DeprecationWarning:pytest_freezegun.*" ]
Warning messages are typically issued in situations where it is useful to alert the user of some condition in a program, where that condition (normally) doesn’t warrant raising an exception and terminating the program. For example, one might want to issue a warning when a program uses an obsolete module.
import warnings def f(): warnings.warn('Message', DeprecationWarning)
To test the function with pytest you can use
import warnings import pytest def test_warning(): with pytest.warns(UserWarning, match='my warning'): warnings.warn("my warning", UserWarning)
You need both
bs = BeautifulSoup(requests.get(url), "lxml")
import traceback traceback_str = ''.join(traceback.format_tb(e.__traceback__))
New: Deprecate flakeheaven in favour of flakeheaven.
It's a fork maintained by the community, instead of an absent code dictator.