-3

let us consider the following PyCharm project which has its own env enter image description here

My goal is to run the test "test_translator_dispatcher_new_format.py" from a bash. How to instruct the cmd to use that venv and its local library?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Carlo Allocca
  • 591
  • 1
  • 7
  • 19
  • Activating the venv is explained in the linked question. Afterwards you should place a `pytest.ini` configuration file [as explained here](https://docs.pytest.org/en/stable/customize.html#pytest-ini) in the root of your project. After activating the venv just run `pytest` at the root folder of your project. The tests inside the `test` folder are indicated to pytest by using the `testpaths = tests` in the `pytest.ini` file. – bad_coder Mar 30 '21 at 16:39
  • Unfortunately it does not.... – Carlo Allocca Mar 30 '21 at 18:16
  • 1
    What "does not"? – bad_coder Mar 30 '21 at 18:17
  • How to instruct the cmd to use that Pycharm venv and its local library included Python. – Carlo Allocca Mar 30 '21 at 18:18
  • Well, there seem to be several questions here. 1º question "using the library" as you put it has several ways of being done, eg. are you using a "development install" or just executing on the local path (your question is unclear about that)? 2º question, activating the venv is, in fact, explained in the linked post. 3º getting pytest to work with a given project is yet another question. All those questions have been answered both separately and together on other threads (and I think on this thread also.) – bad_coder Mar 30 '21 at 18:23

1 Answers1

1
  1. open command prompt from current (project) directory

  2. Then activate the virtual environment using this command:

venv\Scripts\activate

  1. then change directory using this command, in your case directory name is tests:

cd <directory_name>

  1. Run python file using this command:

python test_translator_dispatcher_new_format.py

Akshay Pawar
  • 784
  • 1
  • 7
  • 11
  • Thank you vrey much. Just a clarification: How would I check that the above is using the local library and not anyother? – Carlo Allocca Mar 30 '21 at 14:33
  • I tried this out and it worked....however, there is a limitation to use the activate.bat file which across platform would not work. For example, waht about linux? – Carlo Allocca Mar 30 '21 at 18:17
  • Mac OS / Linux, use this command. source venv/bin/activate, where venv is virtual environment name – Akshay Pawar Mar 31 '21 at 05:51