nosetests skip certain tests in python with multiple tests - shell

I want to skip or exclude some certain tests from the build or the pipeline.
I am running nosetests -s -v * which runs all the tests under some specific folder.
Suppose there are about 30 tests and out of the 5 I want to skip- To do that I am trying
nosetests -s -v * --exclude-test test_sometest.py test_somemoretest.py
or
nosetests -s -v * -- test_sometest.py test_somemoretest.py
but both of them not work for me.
I am referring from here
#!/bin/sh
cd tests/engine_tests/measures
nosetests -s -v * --exclude-test test_sometest1.py test_somemoretest2.py test_sometest3.py test_somemoretest4.py
Any help would be great!!

Add this parameter to your command:
--ignore-files="tests_to_exclude\.py"

python -m pytest --cache-clear -v -x -r a --junit-xml=tests/engine_tests --junit-prefix=measure_tests *.py --deselect Test1\.py --deselect Test2\.py --deselect Test3\.py --deselect Test4\.py
I tried this and it worked for me. Before that You need to install pytest
pip install pytest
Documentation will be find by typing
pytest --help under terminal
or somewhere here

Related

having difficulty installing protocol buffer on ubuntu

I need a specific version of protocol buffer which is 3.14.0 on apt its not available like this
sudo apt install -y protobuf-compiler = 3.14.0
and If I follow these steps by binary :
$ PB_REL="https://github.com/protocolbuffers/protobuf/releases"
$ curl -LO $PB_REL/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip
then
unzip protoc-3.14.0-linux-x86_64.zip -d $HOME/.local
then
$ export PATH="$PATH:$HOME/.local/bin"
from this source
and it's not getting install when I do protoc --version I am getting this error
bash: /usr/bin/protoc: No such file or directory
I think Because /usr/bin/protoc doesn't exist. When you unzipped you got folder named protoc-3.14.0.
which is /usr/bin/protoc-3.14.0
try doing this
PROTOC_ZIP=protoc-3.14.0-linux-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
ref: http://google.github.io/proto-lens/installing-protoc.html
Please check out the following steps to Install protoc on Ubundu, Run the commands 1 to 4 on terminal. Then 5 and 6 to finalize the settings.
Get the latest version tag of protoc release and assign it to variable:
1.
PROTOC_VERSION=$(curl -s "https://api.github.com/repos/protocolbuffers/protobuf/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
curl -Lo protoc.zip "https://github.com/protocolbuffers/protobuf/releases/latest/download/protoc-${PROTOC_VERSION}-linux-x86_64.zip"
Run the following command to extract executable file from a ZIP archive:
sudo unzip -q protoc.zip bin/protoc -d /usr/local
Set execute permission:
sudo chmod a+x /usr/local/bin/protoc
Now protoc command is available for all users as a system-wide command.
We can now check protoc version:
protoc --version
Remove unnecessary ZIP archive:
rm -rf protoc.zip

what is the meaning of pip install -v?

Recently, I seen a command of pip install -v
actually it is
$ git clone https://github.com/NVIDIA/apex
$ cd apex
$ pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
I usually command pip install something
But what is pip install -v?
-v or we can can also use --verbose. Both are same.
-v is used when you want to use or expressed something in more words than are needed.
-v Give more output. Option is additive, and can be used up to 3 times.

Cant't build Jenkins latest within Docker

******** UPDATE *********
Bash script has no errors, checked with https://www.shellcheck.net/
Adding to the Dockerfilethe line
RUN tty | sed -e "s:/dev/::"
Outputs:
No tty
Next line on Dockerfile always fails:
ENTRYPOINT ["/usr/local/bin/jenkins.sh"]
I leave an image in order to clarify. In short, I think I need to attach a tty in some way to the batch script, but dunno how to do it.
Thanks
------------------- OLD CONTENT -------------------
I need to update a Jenkins image to 2.138.2. An excerpt of the original Dockerfile is as follows:
FROM openjdk:8-jdk
RUN apt-get update && apt-get install -y git curl && rm -rf /var/lib/apt/lists/*
# ...
# Use tini as subreaper in Docker container to adopt zombie processes
COPY tini_pub.gpg ${JENKINS_HOME}/tini_pub.gpg
RUN curl -fsSL https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-$(dpkg --print-architecture) -o /sbin/tini \
&& curl -fsSL https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-$(dpkg --print-architecture).asc -o /sbin/tini.asc \
&& gpg --import ${JENKINS_HOME}/tini_pub.gpg \
&& gpg --verify /sbin/tini.asc \
&& rm -rf /sbin/tini.asc /root/.gnupg \
# ...
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
Using this Dockerfile FAILS due to gpg --import statement now needs to be fixed using --no-tty option. So that line remains as follows:
&& gpg --no-tty --import ${JENKINS_HOME}/tini_pub.gpg \
That's not fine since the execution of jenkins.sh now fails in several ways. The code of the script starts as follows:
#! /bin/bash -e
: "${JENKINS_WAR:="/usr/share/jenkins/jenkins.sh
This script is called from the Dockerfile in this line:
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
But now fails with several errors and seems to be impossible to process the file, nor removing the shebang line, nor removing the '-' or the '-e' option. The rest of the file is not processed fine if we change bash to other shell (not odd) nor removing the -e option (if I do that, the entrypoint does not find the jenkins.sh script).
Sumarizing, I've needed to remove a tty from gpg but doing that, I've lost access to bash scripting.
I've checked about the applied workaround, the workaround is described here ( (if I'm right, case is number 8, gpg might write to the tty at some point):
https://lists.gnupg.org/pipermail/gnupg-users/2017-April/058162.html
Is there any way to attach a tty to the entrypointor having any settings in the script in order to allow this work fine?
Thanks.
Finally runned on a Linux VM and no problems. Running it on Windows is the problem.

Hide "Requirement already satisfied" warning

We have a shell script that automatically prepares virtual environment and then runs tests in it. Part of the script installs requirements:
pip install -r requirements.txt
When the script is run multiple times it prints a warning for each requirement:
Requirement already satisfied (use --upgrade to upgrade): discover==0.4.0
...
I need to run the installation step every time in case that someone adds a new requirement. I understand why the warning is displayed. The problem is that it clutters the test output.
Is there a way how to disable/hide this warning?
It worked for me:
pip install -r requirements.txt | grep -v 'already satisfied'
Assuming the errors go to stderr, this bash code should do it:
pip install -r requirements.txt 2> >(grep -v 'Requirement already satisfied' 1>&2)
For more recent versions of 'pip', where errors go to stdout, the above can be simplified to:
pip install -r requirements.txt | grep -v 'already satisfied'
For Windows users landing here this can be resolved in a virtually similar manner using Find
pip install -r requirements.txt | find /V "already satisfied"
and as answered in a Windows specific question the other way is
pip install -r requirements.txt | findstr /V /C:"Requirement already satisfied"

How can I use aria2 with pacman?

I want to make an alias for zsh to download packages by aria2 and install them by pacman,
I don't want to use aria2c by adding xfercommand to pacman.conf because of 2 things:
First my internet connection's speed is low and I don't want pacman go lock for some hours,
Second xfercommand doesn't support multi link downloads.
First off, I use this command to download or upgrade and update by pacman:
sudo pacman -Sp [Package] > ~/Documents/.install&& sudo aria2c -c -x16 -x16 -m16 -k1M -j10 -i ~/Documents/.install -d /var/cache/pacman/pkg
But I don't know how to make it alias in zsh?
Install aria2, then edit /etc/pacman.conf by adding the following line to the [options] section:
XferCommand = /usr/bin/aria2c --allow-overwrite=true --continue=true --file-allocation=none --log-level=error --max-tries=2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf --remote-time=true --summary-interval=60 --timeout=5 --dir=/ --out %o %u
Taking from the aria2 arch wiki, you don't need the intermediary install file, just use the flag -i -. I also had to add sudo to the aria command. Looks like this:
pacman -Sp [package] | sudo aria2c -d /var/cache/pacman/pkg/ -i -
I have an aria2 config, so all other options are there.
From what I've seen, if you use aria2 in the XferCommand, it wouldn't do multiple downloads, just use aria2 one link at a time.
As for using a function, try
mypacman() {
pacman -Sp $1 | sudo aria2c -d /var/cache/pacman/pkg/ -i -
}
The $1 indicates the first thing after the function call will be placed in this place.
Use it like mypacman [package].
Note: It seems the next version of pacman will do parallel downloads out of the box :)
http://allanmcrae.com/
But I won't risk using it right now...

Resources