14

Is there a way to check in a python unit test (or any other script) if it is executed inside the PyCharm IDE or not?

I would like to do some special things in a unit test when it started locally, things I would not like to do when the whole thing is execute on the build server.

Cheers

2
  • Why don't you do the opposite thing and check if your scrip is running on the build server? Using PyCharm is not the only possible way to run your test locally... Commented Apr 21, 2015 at 20:22
  • @yole Cause I often run the build script on my computer and want it to behave like on the build server at this time. Commented Apr 21, 2015 at 20:33

1 Answer 1

33

When running under PyCharm, the PYCHARM_HOSTED environment variable is defined.

isRunningInPyCharm = "PYCHARM_HOSTED" in os.environ
Sign up to request clarification or add additional context in comments.

2 Comments

And similarly, it looks as if: isRunningInSublime3 = os.getenv ("SESSIONNAME") == "Console".
Actually not so, it seems. Ignore my previous comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.