Is there a way in pytest to get rid of the "x tests ran in 0.01s" line in the output? - pytest

I have a usecase in which I use pytest to go over each file and just collect some metadata specific for my tests. I would like to use the output in another tool without having to manually remove the === no tests ran in 0.10s === line from the bottom of the output.
I have tried adding multiple quiet options and --no-summary but neither of them removes this.
I have noticed that if i use --collect-only with -qq this makes it disappear. I thought I could just use this but reading through documentation I haven't found a way to trigger the collect-only behavior other than using:
def pytest_configure(config) -> None:
if config.option.collect_metadata:
config.addinivalue_line("addopts", "--collect-only")
but that doesn't seem to work either.
Is there a way to get rid of all the summary lines including === no tests ran in 0.10s === without writing my own test collector?

Related

Extend list in omegaconf from command line

I have a configuration similar to this from a yaml file
training_variables:
- var1
- var2
I want to extend the list using an additional variable, and I want to do it from the command line. How to do it? It seems not possible but I think it can be very useful if you want to experiment a new setup without changing the configuration file every time. I was wondering something like this:
train.py training_variables=$training_variables+['var3']
This is not supported, and is not planned to be supported in the form you are requesting.
A practical solution is to split your list into two variables and concatenate them in the code.
base_list:
- a
- b
extra_list: []
train.py:
...
combined_list = cfg.base_list + cfg.extra_list
...
$ python train.py 'extra_list=[c,d,e]'
I am not 100% sure the above command line would work with an app using OmegaConf directly but it should work with Hydra 1.0 or newer.

Discord.py mod log setup

I was wondering how one could make a command that sets up a mod log for a certain server, or start logging in one that already exists. This will probably require a database or JSON, anything is fine, as long as I can get it to work. Any help would be appreciated.
The way I would do this is with a .txt file that would contain all of the logs. I would add a line every time an event within the guild occurred, you could configure this to whatever events you wanted.
import datetime
#client.event
async def on_member_join(member):
with open("logs.txt", "a") as logsFile:
logsFile.write("\n[{}] {} just joined the server".format(datetime.datetime.now(),
member.name))
If you are currently using the logging module for discord.py or any other libraries, you can also use it for logging your own messages, either using the same or a separate logger.

Bdd Cucumber issues

I have newly started working on BDD Cucumber. I am using scala for writing test cases. I am trying to use Scenario Outline and passing parameters in step definitions. My code is as follows.
Scenario Outline: Data is parsed and persisted
Given Portal is running
When A data of <type> is received
Then The data of <type> with <Id> should be parsed and persisted
Examples:
| type | Id |
| Personal | 1 |
|Professional | 2 |
Now in my when condition I am trying to get these parameters as follows
When("""^A data of \"([^\"]*)\" is received$""") {
(type: String) =>
//My code
}
Now on running my code I am getting following error everytime.
io.cucumber.junit.UndefinedStepException: The step "A data of Personal is received" is undefined. You can implement it using the snippet(s) below:
When("""A data of Personal is received""") { () =>
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.scala.PendingException()
}
Though I have my code in when. Also If I don't use Scenario Outline then it works fine but I want to use Scenario Outline for my code.
I am using tags in my feature file to run my test cases. When I run my test cases with command sbt test #tag1, test cases executes fine but when all test cases are finished running on cmd I am getting following error:
[error] Expected ';'
[error] #tag1
I tried putting ";" after tag but still getting same error
What is this issue and how I can resolve it?
I have 4-5 feature files in my application. That means 4-5 tags. As of now the test case which I want to run I give path of feature file and "glue" it with step deinition in my Runner Class. How I can provide all the tags in my Runner class so that my application runs all the test cases one by one when started?
You are missing the double quotes around <type>:
When A data of "<type>" is received
Just some general advice.
When cuking keep things as simple as possible, focus on clarity and simplicity, do not worry about repetition.
Your task would be much simpler if you wrote 2 simple scenarios
Scenario: Personal data
Given Portal is running
When personal data is received
Then personal data should be persisted
Scenario: Professional data
...
Secondly don't use tags to run your features, you don't need tags yet.
You can cuke much more effectively if you avoid scenario outlines, regex's, tags, transforms etc. etc.. The main power in Cucumber is using natural language to express yourself clearly. Focus on that and keep it simple ...

What is the full command for gdal_calc in ipython?

I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.

How to generate junit.xml using minil test?

I am using minilla for generating my module scaffold. While it works very well for me, I'd like to get generated junit.xml file with test results when running minil test.
I found that it is possible to specify tap_harness_args in minil.toml configuration file. I tried
[tap_harness_args]
formatter_class = "TAP::Formatter::JUnit"
which ensures that the tests output is formatted in JUnit format. That works well but the output is mixed up with minilla's other output so I can't easily redirect it to a file. Is there a way how to get only the test results to a file? Optimally, I'd still like to see the test results in TAP format in my terminal output at the same time (but I can live without it).
Just a guess: can't you use the a<file.tgz> option in HARNESS_OPTIONS in TAP::Harness::Env?