Pytest hooks flow - pytest

I'm new to pytest and I can't find solution for my question.
I know about some pytest's hooks like pytest_addoption() and pytest_configure()
I'm trying to figure if and how pytest_addoption() runs first and only then pytest_configure().
If anyone know where I can find some information or can share his knowledge.
Thanks!

The flow of the hooks in pytest are specified here:
https://pytest.readthedocs.io/en/2.8.7/_modules/_pytest/hookspec.html
see first line in the docstring below
def pytest_configure(config):
""" called after command line options have been parsed
and all plugins and initial conftest files been loaded.
This hook is called for every plugin.
"""

Related

How can I change the Flutter test file search pattern from "_test"

I'd like flutter_test to find test files without the "_test" suffix. Where can I configure this pattern?
For python with pytest for instance, you'd change this setting in pytest.ini:
testpaths =
tests
python_files = *.py
What's the Dart way of doing this?
I have gone through your question in-depth and I found these things.
I checked the test package and dig deep into the source code to see how they were actually doing the checking for _test.dart files. And I found out that in the pubspec.yaml, they have one dependency called glob (link) which I think they used to filter the files. I went through their code and found these particular lines for it:
Link to this page
I tried to fork the repository and then change the type there but it was still showing the same test files as before. So I tried a different approach.
I tried to look into the VS Code plugin for test to see if I can change the type there but I couldn't found the exact module in which there defining the path. In VS-Code, we have an option in settings.json to search the test files outside of the test folder by this line.
"dart.allowTestsOutsideTestFolder": true
But there weren't any concrete options to change the test file search pattern for it. So my conclusion is if we were able to change the search pattern then we have to change in so many places which could also break some things. Therefore I would suggest to stick to the convention of it.
Within Flutter there is no convenient option, you can specify which test files to execute. But this will result in an very heavy test script.
Such as:
flutter test test/file1.dart test/file2.dart ...
EDIT:
Based on the answer of Cavin Macwan. You can create an file in the root named dart_test.yaml with the following content:
filename: "*.dart"
Note: This only works with dart test and not flutter test

Where to put pytest_generate_tests hook

I've written a decorator that can generate parameterized functions as in the docs
def pytest_generate_tests(metafunc):
if not hasattr(metafunc.function, '_bdd_spec_test_runs'):
return
metafunc.parametrize(('name', 'index'), [(n, i) for (i, n) in enumerate(metafunc.function._bdd_spec_test_runs)])
If I have this at the bottom of the file where tests using my decorator appear it works. If however I move it to its own module (for example alongside the decorator itself) it results in my test not passing through it.
This seems to be because at the time that pytest sees that hook it has not yet collected the tests targeted yet. So Where am I supposed to put this function? Is there some way that I can tell pytest "here, this is the hook you should use after you're done collecting all tests".

Protractor - how to reuse the same spec file for different tests

In my Protractor conf.js file, I'd like to re-use the same spec files multiple times; however, it's seems to not be possible.
Some background:
We are reading test cases from a JSON file, launching reports, then testing grid results and various DOM elements.
All reports have the same format. The primary differences lie in the report titles, data columns, actual data results, etc.
So in my conf.js file, ideally I'd like to re-use the same spec files multiple times - but my understanding is that I cannot do this.
For example, my spec array:
specs: [
'spec/report1-spec.js',
'spec/report-grid-details-spec.js',
'spec/report2-spec.js',
'spec/report-grid-details-spec.js',
'spec/report3-spec.js',
'spec/report-grid-details-spec.js',
]
I've read this post (http://ramt.in/how-to-run-identical-jasmine-specs-multiple-times-with-protractor/ ) where you can move your spec files into a node module, but 1) I don't want to move all specs files there, and 2) it doesn't work anyway when I move even one spec file into a module export file.
If I can't do it, then I'll just move my report-grid-details-spec.js code into a common page object file and call it whenever it's needed.
Just wondering if anyone out there has found a solution to this need to re-use spec files multiple times in one conf.js configuration.
Thank you,
Bob
If I can't do it, then I'll just move my report-grid-details-spec.js code into a common page object file and call it whenever it's needed.
This would probably be the easiest way to approach the problem. Though, I like the idea of putting specs into modules - it is a plus to reusability overall.
The thing is, jasmine does not allow executing the same test in a single test run. And, from what I understand, there is no easy way to change the behavior.
One of the possible workarounds is to completely restart protractor and, hence, recreate the jasmine testing environment so that the next report-grid-details-spec.js would run in a new jasmine environment - this is something that protractor-flake project uses to retry the failing tests (it basically restarts protractor through command-line passing the failing specs as a comma-separated list to the specs argument, source).

Visual Studio Code User Defined Argument

I'm working with visual studio code tasks and can define arguments in a task successfully upfront as follows:
{"version":"0.1.0","command":"example","isShellCommand":true,"tasks":
[{"taskName":"example task","suppressTaskName":true,"args":["examplearg"]}]}
I would like to be able to type in the argument when running the task, as the argument needs to be user defined, is that possible? For example I would like to be able to Run Task from command pallete: example task --myCustomArg.
Not possible. Open an issue in their repo and see what they say.
There is, however, a way to pass the current file. See here.
Your last choice would be to create an extension. You should give it a try as well. 😊

With Buildbot Source Step: why can 'codebase' not be set via Interpolate while 'repourl' can?

I have a factory that I use in several builders and I set builder specific settings via util.Property and util.Interpolate. While this works fine for repourl and branch it simply doesn't work for codebase. The following piece of code shows the source step how I would like to use it in my Buildbot configuration.
factory.addStep(
steps.Git(repourl=util.Interpolate('git://repo_base_path/%(prop:build_repository)s', default=''),
branch=util.Property('build_branch', default='master'),
mode='full',
codebase=util.Interpolate('%(prop:build_repository)s', default=''),
method='copy', submodules=True, clobberOnFailure=True)
)
)
Without the codebase part all worked fine. I then figured I would need to set the codebase for some cases so I added the codebase line, resulting in the following error:
[-] Configuration Errors:
[-] error while parsing config file: sequence item 1: expected
string, Interpolate found traceback in logfile
Does anybody know why it is not possible to set the codebase via Interpolate while it is no problem to do the same thing with repourl?
Does somebody have an idea how to set the codebase for the source step to something different from '' and still not create a separate factory instance for every builder?
Any insights into this and any helpful suggestion is highly appreciated.
I think this is a bug in Buildbot. Looking at the Buildbot 0.8.12 sources, I can see that in buildbot/steps/source/git.py, in class Git, the renderables attribute includes "codebase", which should mean that you can use Interpolate in this way. Presumably some other code is assuming it can interpret codebase as a string at the time the configuration is parsed.
In other words, as far as I can tell, you're doing something that the Git class claims to support.
It looks like the old-style Git support in buildbot/steps/source/oldsource.py doesn't support codebase being a renderable, but it doesn't look to me like you're using that. I'm not entire sure, though, because I'm not sure what steps.Git refers to.