user3243499
user3243499

Reputation: 3161

How to specify a particular conda environment to run pytest code against?

I have created some tests in Tests.py using py.test framework.

And I am using the following bash command to run in terminal:

py.test --junitxml result_Tests.xml Tests.py

But in this case py.test is picking the default python installation.

How do I specify a conda environment name to py.test so that it runs on that specific conda environment?

I could not find any specific py.test switches in their docs.

Upvotes: 9

Views: 7860

Answers (2)

mosegui
mosegui

Reputation: 721

The proper manner to specify the conda environment in which a command must run is using the conda run command, passing the env name with the -n flag. In your case:

conda run -n <env_name> pytest tests.py --junitxml result_Tests.xml

Upvotes: 5

0xDBFB7
0xDBFB7

Reputation: 262

This is pretty obvious and probably not what you're looking for, but - assuming 'python' is the conda environment's - using

python -m pytest 

seems to work.

Upvotes: 11

Related Questions