1

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?

Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
Josiki
  • 115
  • 1
  • 1
  • 8

1 Answers1

1

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:

dkreeft
  • 642
  • 5
  • 17
  • 1
    Great, thanks! I ended up using conda, and just setting the python interpreter to the conda one. – Josiki Jun 07 '20 at 06:46