Day 1009
Google Meet
You can minimize your own video, and then make the entire window much smaller!
Python strings formatting
Obvious, but: you can declare strings and format them in separate places!
constants.py
:
my_string = "Hello my name is {0}"
other_file.py
:
from constants import my_string
print(my_string.format("Serhii"))
Pycharm run current unittest binding
<C-S-F10>
runs the unittest where the cursor is currently located. Or all of them if located anywhere else in the file.
TODO: set binding to do the same, but debugging.
python - run only some tests from a test suite
I wanted to run only some test files, all except the ones where I needed a GPU. Wrote this:
import subprocess
# Parts of filenames to exclude
large_tests = ['component', 'test_temp']
test_folder = Path(__file__).parent.absolute()
test_files = list(test_folder.glob("test_*.py"))
test_files = [x.name for x in test_files]
for l in large_tests:
test_files = list(filter(lambda x: l not in x, test_files))
commands = ["python3", "-m", "unittest"] + test_files
subprocess.run(commands, cwd=test_folder)
Notes:
- Thought this would be a security nightmare, but it’s not1 - unless
shell=True
is explicitly passed, no shell is called, ergo no shell-command-injection stuff is possible. os.chdir()
is nicely replaced by thecwd=
parameter, much nicer than what I’d have done previously!
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus