Using pytest from a BAT file [duplicate] - python

This question already has answers here:
How to start Python virtual environment in .bat batch file?
(2 answers)
Closed 2 years ago.
I am trying to using pytest from a BAT file. I have tried something like this
..\venv\Scripts\activate.bat
pytest -v src/datasets_test.py::TestDatasetsOperations::test_dataset_add
But it seems to do nothing. How can I make it work?
EDIT: the question is similar, but no one will go to other question if he thinks the error is with pytest

In order to call another script from a batch script, you need to use call.
call ..\venv\Scripts\activate.bat
pytest -v src/datasets_test.py::TestDatasetsOperations::test_dataset_add

Related

Environment Variables returning None when running Python script from Cron [duplicate]

This question already has answers here:
Environment variable used in shell script appear blank in log file when run by cron
(3 answers)
Closed 1 year ago.
I have set my environment variables in /etc/profile and ~/profile. When I run an echo $EVNAME it returns correctly but running it as a Cron job returns None.
I'm running it on Raspberry Pi 4 and script using Python3.
Any help with this one?
The proper path for the profile file is /etc/profile. If you're intending to set it to a specific user, it's ~/.bashrc.
See here: https://linuxize.com/post/how-to-set-and-list-environment-variables-in-linux/#persistent-environment-variables

how to run command line python scripts within my code [duplicate]

This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 2 years ago.
there are some scripts that you have to run them from command line like
python run.py -u alex__a -p 123 -v -f
I want to work with them inside my code I don't know whats the name of them so I wasn't able to google about my question . sorry if it't so simple
You are looking for sys.argv to access them. Here is a tutorial:
https://www.pythonforbeginners.com/system/python-sys-argv
If you want to get more serious and use a package to do this more elegantly, you should research the argparse package which is excellent and very intuitive to use.

How to keep a terminal opened by Python alive? [duplicate]

This question already has answers here:
How to keep a Python script output window open?
(27 answers)
Closed 3 years ago.
In my Python script, I create a .bat file (many actually), and I run them via
os.startfile(blah)
Everything works like expected, however, those terminals die after finishing. I want to keep them open, so that I can type more commands manually in those opened terminals.
How?
You could try using the cmd command to run the batch file, and then use command line arguments for cmd to modify its behavior. For example:
os.startfile("cmd.exe /k blah.bat")
Documentation of the available command line arguments can be found here:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd

How to configure in .vimrc , execute current file python f9? [duplicate]

This question already has answers here:
Running Python code in Vim
(25 answers)
Closed 5 years ago.
I'm newbie in this editor but it's complex to configure vimrc. I know and understand that everything stay there but I don't understand how to configure, specifically the code. On the other hand, I am writing Python code using Vim. Every time I want to run my code, I type this inside Vim
:w !python
This gets frustrating, so I was looking for a quicker method to run Python code inside Vim. If somebody can I help me, I would be very grateful.
You've very close. The following works in my config:
nnoremap <F9> :w<cr>:!python %<cr>
First, it enters the command to save the file (:w). Then it tells the shell to have python (!python) run the current file (%).

Is there anything like "set -x" in python [duplicate]

This question already has answers here:
What is the Python equivalent of `set -x` in shell?
(4 answers)
Closed 5 years ago.
I'd like to run my python script in such a way that every line is printed as it is executed (for debugging purposes), like how you can add set -x to a bash script. Is this possible? If not, what other strategies are there for debugging python that don't involve adding log lines everywhere? I usually use pdb but this isn't always suitable for time sensitive applications eg networking.
Use the trace module.
$ python -m trace -t myscript.py | grep myscript.py

Categories