Josiki
Josiki

Reputation: 115

Running pytest in VS code when needing to load modules beforehand

I am trying to use pytest within VS code, running in red hat linux. The environment that I am using means that I need to load modules such as pandas before running pytest. In the terminal I can run:

module load pandas
pytest

and the tests are successfully run. I can do this in both the standard terminal, in the Python Debug Console within VS code, and int he bash terminal within VS code. If, however, I press the "Run All Tests" button within VS code, then I just get an error telling me that it cannot find the pandas module.

How can I tell the test environment to run my module load pandas command before running pytest?

Upvotes: 1

Views: 1234

Answers (1)

dkreeft
dkreeft

Reputation: 682

In this case I would create a file named conftest.py in the directory containing the tests. pytest automatically executes this file before the tests are run. In this file you could have Python execute shell commands. For the latter there are different options, but first try one of the easier ones.

More information on conftest.py:

Upvotes: 2

Related Questions