1

Adding a directory to the PATH variable can be as simple as running export PATH=$PATH:/path/to/dir. What I'm trying to achieve is to have pytest run this command before anything else happens so that I can set the browser drivers to PATH (instead of moving them to /usr/local/bin as I prefer to change PATH temporarily).

Couple obvious workarounds are:

  • Manually executing the above command before starting pytest
  • Using a separate Python file to wrap around pytest

My attempt after looking through several SO posts was to play around with various pytest_ methods such as pytest_configure in conftest.py but this did not work as pytest failed to see the specified directory in PATH.

Is there a way to incorporate this command into pytest framework so I don't have to explore these workarounds?

mysl
  • 650
  • 1
  • 6
  • 14
  • https://stackoverflow.com/q/1681208/2650249 – hoefling May 15 '20 at 23:10
  • @hoefling Unfortunately, this is equivalent to `export PATH=$PATH:/path/to/dir` with `os.system` wrapped around it, which I initially mentioned in the post. I'm trying to find a way within the Pytest/Selenium framework to set the PATH before running tests or spinning up Selenium drivers. Please help! – mysl May 16 '20 at 02:55
  • `conftest.py` gets run before any test does. Following the procedure @hoefling links in the top-level `conftest.py` should have the desired effect. – Kyle Parsons May 18 '20 at 15:01
  • @KyleParsons As mentioned in the original post, setting the PATH variable via `pytest_configure(config)` method in `conftest.py` did not yield the desired effect because the Selenium drivers were spun up before the new PATH was set – mysl May 18 '20 at 19:11

0 Answers0