Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest and Python 3

I've installed pytest 2.3.4 under Debian Linux. By default it runs under Python 2.7, but sometimes I'd like to run it under Python 3.x, which is also installed. I can't seem to find any instructions on how to do that.

The PyPI Trove classifiers show Python :: 3 so presumably it must be possible. Aside from py.test somedir/sometest.py, I can use python -m pytest ..., or even python2.7 -m pytest ..., but if I try python3 -m pytest ... I get

/usr/bin/python3: No module named pytest

like image 676
Joe Abbate Avatar asked Jan 17 '13 02:01

Joe Abbate


People also ask

What version of Python does pytest use?

For those reasons, in Jun 2019 it was decided that pytest 4.6 series will be the last to support Python 2.7 and 3.4.

Is pytest included in Python?

The pytest package differentiates itself from other python testing packages such as unittest and nose due to its straightforward syntax. It uses a single assert statement instead of numerous assertSomething commands found in unittest .


1 Answers

I found a workaround:

  1. Installed python3-pip using aptitude, which created /usr/bin/pip-3.2.
  2. Next pip-3.2 install pytest which re-installed pytest, but under a python3.2 path.
  3. Then I was able to use python3 -m pytest somedir/sometest.py.

Not as convenient as running py.test directly, but workable.

like image 183
Joe Abbate Avatar answered Sep 22 '22 18:09

Joe Abbate