Registered INI value not being used
I am trying to set the INI file option
testpaths based off of command line input. I correctly parse the value out, and then set the value with
config.addinivalue_line("testpaths",test_directory_path) but pytest collect all tests instead of the test directory I want.
Does any one have an idea of why this wouldn't be working?
See also questions close to this topic
How to get new and modified data from two different sources in Python
I have large datasets from 2 sources, one is a huge csv file and the other coming from a txt file. Source 1 (CSV file):
id,name,address 00001,Jack,LA 00002,Jayce,CA 00003,Tony,GA 00004,Katar,CA 00005,Henry,GA
Source 2 (txt file)
00001|Jack |CA 00002|Jayce|CA 00003|Tony |LA 00004|Katar|CA 00005|Henry|HI 00006|Darick|GA
The output of the script I want is something like:
00001|Jack |CA 00003|Tony |LA 00005|Henry|HI 00006|Darick|GA
The CSV file is a historical data, and the txt file is a new data. I want to compare and get only the new and modified data. In my case, the data in those files are really big (up to 1000000 lines) and I have no idea to do. Could anyone can help me?
yesterday at hours:minute to datetime
I have datetime like : Yesterday at 10:50 PM, and I try to convert it to python datetime, I've already tried to use
timedelta(days=1)and change the hours and minute but is there any better way to do that ?
I'm trying to display an image in Python 3.7.0 using Jupyter Notebook. Why isn't it working?
The image is called "pythontest.png". I'm trying to display the image using the following code:
from IPython.display import Image img = 'pythontest.png' Image(url=img) print(Image)
but when I run the program it simply displays:
What does that mean and how do I make it display the actual image? Thanks.
Pytest: pass one fixture to another
Is it possible to pass one fixture object to another in Pytest? For example, suppose I want to have two fixture objects: one that's a numpy array, and another that's some model of that array:
import pytest import numpy as np @pytest.fixture() def arr(): np.random.seed(141) return np.random.seed(141) @pytest.fixture() def model(arr): return arr * 2 def test_multiplication(arr, model): assert model == arr * 2
NoneTypeinside model, which confuseth me.
The use case for this is a case where some tests need access to the raw
arritself, while others need access to the models.
To make this work, however, one needs to pass one fixture to another (so we can build the model using the array). Is this possible? Any help others can offer would be greatly appreciated!
Python Coverage - not covering function contents, just definition
I am using
coverage.pyto test my code coverage. My tests are passing, however, when I call
coverage run -- [script].py -m [test_script].py
and generate a report it indicates that
<line hits="1" number="5"/> <line hits="0" number="6"/> <line hits="0" number="7"/> <line hits="0" number="8"/>
Where line 5,6,7 and 8 are as follows:
def __init__(self, data): self.left = None self.right = None self.data = data
For another example:
My test code:
def test_arb(): assert tree.inc(3) == 4
def inc(x): return x+1
and the result on the report
<line hits="1" number="48"/> <line hits="0" number="49"/>
I've spent days researching this and can't seem to find a straightforward answer. Would anyone be able to help? It may be an obvious fix but I am a beginner at Python and testing.
pytest-django add fixtures to live_server fixture
I need to add fixtures to the
live_serverfixture provided by
pytest-djangospecifically an overwritten
That being said I understand it is not ideal to run tests against a db that isn't flushed clean but it is what I am working with.
In our normal test suite we use overwrite the
django_db_setupto do nothing in our
conftest.pyfile as follows
@pytest.fixture(scope="session") def django_db_setup(): pass
It appears that when I use the
live_serverfixture provided by
pytest-djangoit does not honor this as it attempts to flush the db at the end of the tests. How would one go about circumventing this? I've found an end around shown below but I'd like to avoid it if there is a better solution.
@pytest.fixture(scope='session') def my_live_server(request): request.getfixturevalue('django_db_setup') return live_server(request)
Read INI File in a thread without consuming CPU time
How can I read an
.inifile in a thread without consuming so much CPU time? The thread will run at runtime, this means while true without delay.
The code to search the value on .ini is:
var Leitura : TIniFile; begin Result := False; Leitura := TIniFile.Create('File.ini'); if Leitura.ValueExists('KEY', ValueToSearch) then Result := True; Leitura.Free;
but since this function runs in an infinite loop, it consumes CPU time, and I need solve this question.
shell_exec works in terminal, but not in the browser
Here's my PHP code:
$command = escapeshellcmd('echo hello'); $output = shell_exec($command); echo $output;
When I run this in terminal, it outputs
hellolike it's supposed to:
But when I visit
example.com/test.phpnothing is output.
I'm guessing it has something to do with the use of
shell_exec, but I'm not getting any error messages and don't understand why the PHP file would work in terminal but not in the browser.
I don't have access to edit the root php.ini file, but I can create a user-level php.ini file to make custom changes.
Add details related to possible duplicates below.
Does tox.ini need escaping for anchors in URLs (hash #)?
I have a tox.ini like this
[tox] skipsdist = True envlist = begin,py35,py36,end [testenv] commands = pip install -e git+ssh://firstname.lastname@example.org/org/repo#egg=repo[server]
and I get the error
Could not detect requirement name for 'git+ssh://email@example.com/org/repo.git', please specify one with #egg=your_package_name
It looks very much as if the
#is treated as a comment. Is that the case? How can I escape it?
What I tried
\#: The \ is recognized, but not the rest - so it is not an escape character
- Quoting the whole string:
ERROR: InvocationError: could not find executable 'pip install -e git+ssh://firstname.lastname@example.org/org/repo.git#egg=repo[server]'