Home > Enterprise >  Regex include pattern but exclude subsequent pattern
Regex include pattern but exclude subsequent pattern

Time:12-22

I'm losing my mind over a regex situation. I have a log file from unittests and use regex to assert that the proper tests have passed.

An excerpt from the log file;

pydicom/pydicom/tests/test_filereader.py::test_read_dicomdir_deprecated PASSED
pydicom/pydicom/tests/test_filereader.py::TestReadDataElement::test_read_SV_explicit_little SKIPPED
pydicom/pydicom/tests/test_filereader.py::TestDSISnumpy::test_IS_numpy_import_error SKIPPED
pydicom/pydicom/tests/test_filereader.py::TestDSISnumpy::test_DS_numpy_import_error SKIPPED
pydicom/pydicom/tests/test_filereader.py::TestDSISnumpy::test_numpy_import_warning SKIPPED
pydicom/pydicom/tests/test_waveform.py::TestHandlerGenerateMultiplex::test_as_raw PASSED

So firstly, I'm only interested in the tests from pydicom/pydicom/tests/test_filereader.py. These I can find with r"pydicom/tests/test_filereader.py.*". Now, I'm loosing my mind trying to implement a negative lookbehind for the skipped tests (I've vetted that the tests are legitimately skipped).

CodePudding user response:

(?!.*SKIPPED)pydicom/tests/test_filereader.py.*

You can try this.See demo. https://regex101.com/r/1A53yy/1

  • Related