This can be done (using option 2 below) but not using the GUI shown in the question (option 1). It must be noticed there are 2 very different ways to launch the Console inside PyCharm.
1. As shown in the question by going to File > Settings > Build, Execution, Deployment > Console > Python Console.
2. Or using the Run/Debug configuration at Run > Edit Configurations.
What the GUI does in the 2 cases is very different
1. In the first case, the IDE simply calls the OS shell with the Python interpreter as first argument and the path to the Console plugin as second argument.
C:\path_to_venv\Scripts\python.exe
"C:\JetBrains\PyCharm 2020.1.1\plugins\python\helpers\pydev\pydevconsole.py"
--mode=client --port=12345
There is one single variable of IDE magic to this (see also the comments in this answer):
Console. Python Console
The WORKING_DIR_AND_PYTHON_PATHS variable is hardcoded in PyCharm. It displays two paths: the project root and the working directory.
This means the IDE does not expose any other "magic variable" that would allow to retrieve the file before or after the Interpreter/Console is being called. Neither Python nor the OS have any way of knowing at this point what file/module you want to use, the only way would be hardcoding the file path as an environment variable (but this doesn't solve anything, because you would have to change the path every time you change file.)
2. The second option, does allow to transparently pass the module/file you currently have opened in the editor when you call the Console.
Basically by creating a run/configuration "template" using a using the "FileDir macro" whenever you run the debugger on any module opened in the editor a "temporary configuration" is created for that module that allows to retrieve the macro value from sys.argv. In this case the file is chosen by the IDE on-the-fly and the macro passes the path along with it.
C:\path_to_venv\Scripts\python.exe
"C:\JetBrains\PyCharm 2020.1.1\plugins\python\helpers\pydev\pydevd.py"
--multiproc --qt-support=auto --client 127.0.0.1 --port 12345
--file C:/path_to_module/teste2.py C:\path_to_module
This 2nd option is how the Console is supposed to be used in PyCharm to get the functionality in the question, as shown in the screenshot.

os.path.dirname(os.path.realpath(__file__))sys.path.extend(['/Users/steve/git/deepteam',os.path.dirname(os.path.realpath(__file__))]) NameError: name '__file__' is not defined